Skip to content

Commit

Permalink
fix: LinkedIn OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Dec 6, 2023
1 parent 86307e3 commit db47a65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
33 changes: 7 additions & 26 deletions recipe/thirdparty/providers/linkedin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
},
}

Expand Down
2 changes: 1 addition & 1 deletion supertokens/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit db47a65

Please sign in to comment.