Skip to content

Commit

Permalink
feat: Parse screenName in ProvidedUserInfo
Browse files Browse the repository at this point in the history
This is available when having multiple providers where it provides
a screen name such as Twitter or GitHub.

See
https://cloud.google.com/identity-platform/docs/reference/rest/v1/ProviderUserInfo
for details.

It's available at endpoints like accounts.lookup or
projects.queryAccounts

Signed-off-by: Enrique J. Hernández <sixstone-qq@users.noreply.github.com>
  • Loading branch information
sixstone-qq committed Dec 18, 2024
1 parent afeaa15 commit 66aaf2b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type UserInfo struct {
// In UserRecord.UserInfo it will return the constant string "firebase".
ProviderID string `json:"providerId,omitempty"`
UID string `json:"rawId,omitempty"`
// ScreenName is the user's screen name at Twitter or login name at GitHub.
// Only populated in ProviderUserInfo[]
ScreenName string `json:"screenName,omitempty"`
}

// multiFactorInfoResponse describes the `mfaInfo` of the user record API response
Expand Down
8 changes: 8 additions & 0 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ var testUser = &UserRecord{
ProviderID: "phone",
PhoneNumber: "+1234567890",
UID: "testuid",
}, {
ProviderID: "github",
ScreenName: "login",
UID: "testuid",
},
},
TokensValidAfterMillis: 1494364393000,
Expand Down Expand Up @@ -1926,6 +1930,10 @@ func TestMakeExportedUser(t *testing.T) {
ProviderID: "phone",
PhoneNumber: "+1234567890",
UID: "testuid",
}, {
ProviderID: "github",
ScreenName: "login",
UID: "testuid",
}},
MFAInfo: []*multiFactorInfoResponse{
{
Expand Down
5 changes: 5 additions & 0 deletions testdata/get_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"providerId": "phone",
"phoneNumber": "+1234567890",
"rawId": "testuid"
},
{
"providerId": "github",
"screenName": "login",
"rawId": "testuid"
}
],
"photoUrl": "http://www.example.com/testuser/photo.png",
Expand Down
10 changes: 10 additions & 0 deletions testdata/list_users.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"providerId": "phone",
"phoneNumber": "+1234567890",
"rawId": "testuid"
},
{
"providerId": "github",
"screenName": "login",
"rawId": "testuid"
}
],
"photoUrl": "http://www.example.com/testuser/photo.png",
Expand Down Expand Up @@ -66,6 +71,11 @@
"providerId": "phone",
"phoneNumber": "+1234567890",
"rawId": "testuid"
},
{
"providerId": "github",
"screenName": "login",
"rawId": "testuid"
}
],
"photoUrl": "http://www.example.com/testuser/photo.png",
Expand Down

0 comments on commit 66aaf2b

Please sign in to comment.