Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix user info link to user info #1899

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 21 additions & 39 deletions src/adapters/oauth2/linkedinAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class LinkedinAdapter implements SocialNetworkOauth2AdapterInterface {
*/

// https://docs.microsoft.com/en-us/linkedin/shared/authentication/getting-access?context=linkedin%2Fcontext#open-permissions-consumer
const scope = 'profile';
const scope = 'openid profile email';
return `https://www.linkedin.com/oauth/v2/authorization?client_id=${clientId}&redirect_uri=${redirectUrl}&response_type=code&scope=${scope}&state=${trackId}`;
}

Expand Down Expand Up @@ -57,50 +57,32 @@ export class LinkedinAdapter implements SocialNetworkOauth2AdapterInterface {
const accessToken = result.data.access_token;

/**
* @see {@link https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin%2Fconsumer%2Fcontext#api-request}
*/
const meResult = await axios.get('https://api.linkedin.com/v2/me', {
@see {@link https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext#api-request-to-retreive-member-details}
*/
const meResult = await axios.get('https://api.linkedin.com/v2/userinfo', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

/**
* sample response
{
"id":"REDACTED",
"firstName":{
"localized":{
"en_US":"Tina"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"lastName":{
"localized":{
"en_US":"Belcher"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:B54328XZFfe2134zTyq"
}
}
* New Sample response
* {
* "sub": "782bbtaQ",
* "name": "John Doe",
* "given_name": "John",
* "family_name": "Doe",
* "picture": "https://media.licdn-ei.com/dms/image/C5F03AQHqK8v7tB1HCQ/profile-displayphoto-shrink_100_100/0/",
* "locale": "en-US",
* "email": "[email protected]",
* "email_verified": true
* }
*/
const username = meResult.data.id;
let name = username;
if (
meResult.data?.firstName?.localized?.en_US ||
meResult.data?.lastName?.localized?.en_US
) {
name = `${meResult.data?.firstName?.localized?.en_US || ''} ${
meResult.data?.lastName?.localized?.en_US || ''
}`.trim();
}
const username = meResult.data.sub;

const name =
meResult.data.name ||
`${meResult.data.given_name || ''} ${meResult.data.family_name || ''}`.trim();
return {
username,
name,
Expand Down
Loading