From db47a65616a4e8f6a01c49fb0417451164cd49bd Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 6 Dec 2023 12:00:04 +0530 Subject: [PATCH] fix: LinkedIn OAuth --- CHANGELOG.md | 5 +++- recipe/thirdparty/providers/linkedin.go | 33 ++++++------------------- supertokens/constants.go | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a8bcd92..753b3ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.17.2] - 2023-12-06 + +- Updates LinkedIn OAuth implementation as per the latest [changes](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext#authenticating-members). ## [0.17.1] - 2023-11-24 @@ -181,7 +184,7 @@ If you were using the SDK Versions < `0.13.0`, use the following override functi - Only supporting FDI 1.17 - Core must be upgraded to 6.0 - For consistency, all `UnknownUserIDError` have been renamed to `UnknownUserIdError` -- `getUsersOldestFirst` & `getUsersNewestFirst` has mandatory parameter `tenantId`. Pass `'public'` if not using multitenancy. +- `getUsersOldestFirs't` & `getUsersNewestFirst` has mandatory parameter `tenantId`. Pass `'public'` if not using multitenancy. - Added mandatory field `tenantId` to `EmailDeliveryInterface` and `SmsDeliveryInterface`. Pass `'public'` if not using multitenancy. - Removed deprecated config `createAndSendCustomEmail` and `createAndSendCustomTextMessage`. - EmailPassword recipe changes: diff --git a/recipe/thirdparty/providers/linkedin.go b/recipe/thirdparty/providers/linkedin.go index 8b0da2e1..f28fc9e3 100644 --- a/recipe/thirdparty/providers/linkedin.go +++ b/recipe/thirdparty/providers/linkedin.go @@ -31,7 +31,8 @@ func Linkedin(input tpmodels.ProviderInput) *tpmodels.TypeProvider { } if len(config.Scope) == 0 { - config.Scope = []string{"r_emailaddress", "r_liteprofile"} + // https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext#authenticating-members + config.Scope = []string{"openid", "profile", "email"} } return config, nil @@ -47,38 +48,18 @@ func Linkedin(input tpmodels.ProviderInput) *tpmodels.TypeProvider { "Authorization": "Bearer " + accessToken, } rawUserInfoFromProvider := tpmodels.TypeRawUserInfoFromProvider{} - userInfoFromAccessToken, err := doGetRequest("https://api.linkedin.com/v2/me", nil, headers) + // https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext#sample-api-response + userInfoFromAccessToken, err := doGetRequest("https://api.linkedin.com/v2/userinfo", nil, headers) if err != nil { return tpmodels.TypeUserInfo{}, err } rawUserInfoFromProvider.FromUserInfoAPI = userInfoFromAccessToken.(map[string]interface{}) - emailAPIURL := "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))" - userInfoFromEmail, err := doGetRequest(emailAPIURL, nil, headers) - if err != nil { - return tpmodels.TypeUserInfo{}, err - } - - elements := userInfoFromEmail.(map[string]interface{})["elements"].([]interface{}) - for _, elem := range elements { - if elemMap, ok := elem.(map[string]interface{}); ok { - for k, v := range elemMap { - if k == "handle~" { - emailMap := v.(map[string]interface{}) - rawUserInfoFromProvider.FromUserInfoAPI["email"] = emailMap["emailAddress"] - } - } - } - } - - for k, v := range userInfoFromEmail.(map[string]interface{}) { - rawUserInfoFromProvider.FromUserInfoAPI[k] = v - } - userInfoResult := tpmodels.TypeUserInfo{ - ThirdPartyUserId: rawUserInfoFromProvider.FromUserInfoAPI["id"].(string), + ThirdPartyUserId: rawUserInfoFromProvider.FromUserInfoAPI["sub"].(string), Email: &tpmodels.EmailStruct{ - ID: rawUserInfoFromProvider.FromUserInfoAPI["email"].(string), + ID: rawUserInfoFromProvider.FromUserInfoAPI["email"].(string), + IsVerified: rawUserInfoFromProvider.FromUserInfoAPI["email_verified"].(bool), }, } diff --git a/supertokens/constants.go b/supertokens/constants.go index 2f4f72de..d6b164d7 100644 --- a/supertokens/constants.go +++ b/supertokens/constants.go @@ -21,7 +21,7 @@ const ( ) // VERSION current version of the lib -const VERSION = "0.17.1" +const VERSION = "0.17.2" var ( cdiSupported = []string{"3.0"}