From 502f91ef166fd389d635d530fb711ef916bee048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez?= Date: Tue, 9 Apr 2024 12:51:46 +0200 Subject: [PATCH] feat: Parse screenName in ProvidedUserInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- auth/user_mgt.go | 3 +++ auth/user_mgt_test.go | 8 ++++++++ testdata/get_user.json | 5 +++++ testdata/list_users.json | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/auth/user_mgt.go b/auth/user_mgt.go index 601c1e03..a5ea5787 100644 --- a/auth/user_mgt.go +++ b/auth/user_mgt.go @@ -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 diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index ffa48655..71266e9d 100644 --- a/auth/user_mgt_test.go +++ b/auth/user_mgt_test.go @@ -57,6 +57,10 @@ var testUser = &UserRecord{ ProviderID: "phone", PhoneNumber: "+1234567890", UID: "testuid", + }, { + ProviderID: "github", + ScreenName: "login", + UID: "testuid", }, }, TokensValidAfterMillis: 1494364393000, @@ -1926,6 +1930,10 @@ func TestMakeExportedUser(t *testing.T) { ProviderID: "phone", PhoneNumber: "+1234567890", UID: "testuid", + }, { + ProviderID: "github", + ScreenName: "login", + UID: "testuid", }}, MFAInfo: []*multiFactorInfoResponse{ { diff --git a/testdata/get_user.json b/testdata/get_user.json index 0bf86f95..84837fe8 100644 --- a/testdata/get_user.json +++ b/testdata/get_user.json @@ -20,6 +20,11 @@ "providerId": "phone", "phoneNumber": "+1234567890", "rawId": "testuid" + }, + { + "providerId": "github", + "screenName": "login", + "rawId": "testuid" } ], "photoUrl": "http://www.example.com/testuser/photo.png", diff --git a/testdata/list_users.json b/testdata/list_users.json index 2b630686..77742ba5 100644 --- a/testdata/list_users.json +++ b/testdata/list_users.json @@ -20,6 +20,11 @@ "providerId": "phone", "phoneNumber": "+1234567890", "rawId": "testuid" + }, + { + "providerId": "github", + "screenName": "login", + "rawId": "testuid" } ], "photoUrl": "http://www.example.com/testuser/photo.png", @@ -66,6 +71,11 @@ "providerId": "phone", "phoneNumber": "+1234567890", "rawId": "testuid" + }, + { + "providerId": "github", + "screenName": "login", + "rawId": "testuid" } ], "photoUrl": "http://www.example.com/testuser/photo.png",