From 12d7febc184e1b862b56b01ffc235f952f16cf6a Mon Sep 17 00:00:00 2001 From: Caceresenzo Date: Tue, 22 Oct 2024 22:24:17 +0200 Subject: [PATCH] feat(model/linked-account): add github oauth class --- .../privy/model/LinkedAccount.java | 25 +++++++++ .../privy/model/LinkedAccountTest.java | 52 ++++++++++++++----- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/privy-client/src/main/java/dev/caceresenzo/privy/model/LinkedAccount.java b/privy-client/src/main/java/dev/caceresenzo/privy/model/LinkedAccount.java index 74395b9..812b7e3 100644 --- a/privy-client/src/main/java/dev/caceresenzo/privy/model/LinkedAccount.java +++ b/privy-client/src/main/java/dev/caceresenzo/privy/model/LinkedAccount.java @@ -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 { @@ -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) diff --git a/privy-client/src/test/java/dev/caceresenzo/privy/model/LinkedAccountTest.java b/privy-client/src/test/java/dev/caceresenzo/privy/model/LinkedAccountTest.java index 920f1fd..5ea9814 100644 --- a/privy-client/src/test/java/dev/caceresenzo/privy/model/LinkedAccountTest.java +++ b/privy-client/src/test/java/dev/caceresenzo/privy/model/LinkedAccountTest.java @@ -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 } """); @@ -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": "johndoe@example.com", + "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("johndoe@example.com", 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 } """);