Skip to content

Commit

Permalink
feat(model/linked-account): add github oauth class
Browse files Browse the repository at this point in the history
  • Loading branch information
Caceresenzo committed Oct 22, 2024
1 parent 63a4a1b commit 12d7feb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@JsonSubTypes.Type(value = LinkedAccount.Phone.class, name = "phone"),
@JsonSubTypes.Type(value = LinkedAccount.Twitter.class, name = "twitter_oauth"),
@JsonSubTypes.Type(value = LinkedAccount.Discord.class, name = "discord_oauth"),
@JsonSubTypes.Type(value = LinkedAccount.Github.class, name = "github_oauth"),
})
@Data
public abstract sealed class LinkedAccount {
Expand Down Expand Up @@ -172,6 +173,30 @@ public static final class Discord extends LinkedAccount {

}

/** Object representation of a user's Github account. */
@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = true)
public static final class Github extends LinkedAccount {

/** The `sub` claim from the Github-issued JWT for this account. */
@JsonProperty("subject")
private String subject;

/** The username associated with the Github account. */
@JsonProperty("username")
private String username;

/** The email associated with the Github account. */
@JsonProperty("email")
private String email;

/** The name associated with the Github account. */
@JsonProperty("name")
private String name;

}

@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ void discord() {
void twitter() {
final var linkedAccount = read("""
{
"type": "twitter_oauth",
"subject": "123456789",
"name": "John Doe",
"username": "johndoe",
"profile_picture_url": "https://pbs.twimg.com/profile_images/x/x.jpg",
"verified_at": 1725376993,
"first_verified_at": 1725376993,
"latest_verified_at": 1725376993
"type": "twitter_oauth",
"subject": "123456789",
"name": "John Doe",
"username": "johndoe",
"profile_picture_url": "https://pbs.twimg.com/profile_images/x/x.jpg",
"verified_at": 1725376993,
"first_verified_at": 1725376993,
"latest_verified_at": 1725376993
}
""");

Expand All @@ -162,14 +162,42 @@ void twitter() {
assertEquals(date, twitter.getLatestVerifiedAt());
}

@Test
void github() {
final var linkedAccount = read("""
{
"type": "github_oauth",
"subject": "1234567",
"username": "johndoe",
"email": "[email protected]",
"name": "John Doe",
"verified_at": 1725376993,
"first_verified_at": 1725376993,
"latest_verified_at": 1725376993
}
""");

final var github = assertInstanceOf(LinkedAccount.Github.class, linkedAccount);

assertEquals("1234567", github.getSubject());
assertEquals("johndoe", github.getUsername());
assertEquals("[email protected]", github.getEmail());
assertEquals("John Doe", github.getName());

final var date = new Date(1725376993l * 1000);
assertEquals(date, github.getVerifiedAt());
assertEquals(date, github.getFirstVerifiedAt());
assertEquals(date, github.getLatestVerifiedAt());
}

@Test
void other() {
final var linkedAccount = read("""
{
"type": "unsupported",
"subject": "123456789",
"name": "John Doe",
"verified_at": 1725376993
"type": "unsupported",
"subject": "123456789",
"name": "John Doe",
"verified_at": 1725376993
}
""");

Expand Down

0 comments on commit 12d7feb

Please sign in to comment.