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

LinkedIn provider could be simplified #428

Open
jamesread opened this issue Nov 12, 2024 · 0 comments
Open

LinkedIn provider could be simplified #428

jamesread opened this issue Nov 12, 2024 · 0 comments

Comments

@jamesread
Copy link
Collaborator

Hey @nevo-david , I'd been having some problems getting the advertising API authorized on my LinkedIn developers account, so I set about seeing if I could adjust the linkedin provider API to work without it.

I dropped r_basicprofile from the scopes, and also removed calls to /me, which seem to be deprecated in favour of /userinfo. This saves quite a few duplicate calls when setting up the integration.

This at least allows posting to work - I've had a quick scan through the rest of the code and I cannot see where the advertizing API migth be used - do you know? If the advertising API is used, maybe we could hide this behind a feature flag for people that don't have the advertising API enabled?

I'll just post the quick diff below, but in principle if I turned this into a PR, would this work for you?

diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
index 441e908..564918d 100644
--- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
@@ -19,7 +19,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
   identifier = 'linkedin';
   name = 'LinkedIn';
   isBetweenSteps = false;
-  scopes = ['openid', 'profile', 'w_member_social', 'r_basicprofile'];
+  scopes = ['openid', 'profile', 'w_member_social'];
   refreshWait = true;
 
   async refreshToken(refresh_token: string): Promise<AuthTokenDetails> {
@@ -42,19 +42,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
       })
     ).json();
 
-    const { vanityName } = await (
-      await this.fetch('https://api.linkedin.com/v2/me', {
-        headers: {
-          Authorization: `Bearer ${accessToken}`,
-        },
-      })
-    ).json();
-
-    const {
-      name,
-      sub: id,
-      picture,
-    } = await (
+    const userinfo = await (
       await this.fetch('https://api.linkedin.com/v2/userinfo', {
         headers: {
           Authorization: `Bearer ${accessToken}`,
@@ -63,13 +51,13 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
     ).json();
 
     return {
-      id,
+      id: userinfo.sub,
       accessToken,
       refreshToken,
       expiresIn: expires_in,
-      name,
-      picture,
-      username: vanityName,
+      name: userinfo.name,
+      picture: userinfo.picture,
+      username: userinfo.name,
     };
   }
 
@@ -122,6 +110,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
 
     this.checkScopes(this.scopes, scope);
 
+    /*
     const {
       name,
       sub: id,
@@ -133,23 +122,26 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
         },
       })
     ).json();
+    */
 
-    const { vanityName } = await (
-      await this.fetch('https://api.linkedin.com/v2/me', {
+    const userinfo = await (
+      await this.fetch('https://api.linkedin.com/v2/userinfo', {
         headers: {
           Authorization: `Bearer ${accessToken}`,
         },
       })
     ).json();
 
+    console.log("Linkedin userinfo", userinfo);
+
     return {
-      id,
+      id: userinfo.sub,
       accessToken,
       refreshToken,
       expiresIn,
-      name,
-      picture,
-      username: vanityName,
+      name: userinfo.name,
+      picture: userinfo.picture,
+      username: userinfo.name,
     };
   }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant