Skip to content

Commit

Permalink
Add LinkedIn auth provider (strapi#7490)
Browse files Browse the repository at this point in the history
* Add LinkedIn auth provider

Signed-off-by: Khalid Elshafie <abolkog@gmail.com>
Signed-off-by: Garrett Fritz <garrettfritz@garretts-mbp.home>
  • Loading branch information
abolkog authored and Garrett Fritz committed Sep 7, 2020
1 parent 53cff43 commit 1bdce04
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/v3.x/plugins/users-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,40 @@ The use of `ngrok` is not needed.

:::

::: tab LinkedIn

#### Using ngrok

LinkedIn accepts the `localhost` urls. <br>
The use of `ngrok` is not needed.

#### LinkedIn configuration

- Visit the Apps list page <br> [https://www.linkedin.com/developers/apps](https://www.linkedin.com/developers/apps)
- Click on **Create app** button
- Fill the information:
- **App name**: Strapi auth
- **LinkedIn Page**: Enter a LinkedIn page name to associate with the app or click **Create a new LinkedIn Page** to create a new one
- **App Logo**: Upload a square image that is at least 100x100 pixels.
- Click on the **Create app** to create the app
- On the app page click on **Auth** tab
- Fill the information:
- **Authorized redirect URL**: `http://localhost:1337/connect/linkedin/callback`
- On the app page click on **Products** tab.
- Select `Sign In with LinkedIn` from the product list to enable it.

#### Strapi configuration

- Visit the User Permissions provider settings page <br> [http://localhost:1337/admin/plugins/users-permissions/providers](http://localhost:1337/admin/plugins/users-permissions/providers)
- Click on the **LinkedIn** provider
- Fill the information:
- **Enable**: `ON`
- **Client ID**: 84witsxk641rlv
- **Client Secret**: HdXO7a7mkrU5a6WN
- **The redirect URL to your front-end app**: `http://localhost:3000/connect/linkedin/redirect`

:::

::::

Your configuration is done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ module.exports = async () => {
callback: `${strapi.config.server.url}/auth/twitch/callback`,
scope: ['user:read:email'],
},
linkedin: {
enabled: false,
icon: 'linkedin',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/linkedin/callback`,
scope: ['r_liteprofile', 'r_emailaddress'],
},
};
const prevGrantConfig = (await pluginStore.get({ key: 'grant' })) || {};
// store grant auth config to db
Expand Down
63 changes: 63 additions & 0 deletions packages/strapi-plugin-users-permissions/services/Providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,69 @@ const getProfile = async (provider, query, callback) => {
});
break;
}
case 'linkedin': {
const linkedIn = purest({
provider: 'linkedin',
config: {
linkedin: {
'https://api.linkedin.com': {
__domain: {
auth: [{ auth: { bearer: '[0]' } }],
},
'[version]/{endpoint}': {
__path: {
alias: '__default',
version: 'v2',
},
},
},
},
},
});
try {
const getDetailsRequest = () => {
return new Promise((resolve, reject) => {
linkedIn
.query()
.get('me')
.auth(access_token)
.request((err, res, body) => {
if (err) {
return reject(err);
}
resolve(body);
});
});
};

const getEmailRequest = () => {
return new Promise((resolve, reject) => {
linkedIn
.query()
.get('emailAddress?q=members&projection=(elements*(handle~))')
.auth(access_token)
.request((err, res, body) => {
if (err) {
return reject(err);
}
resolve(body);
});
});
};

const { localizedFirstName } = await getDetailsRequest();
const { elements } = await getEmailRequest();
const email = elements[0]['handle~'];

callback(null, {
username: localizedFirstName,
email: email.emailAddress,
});
} catch (err) {
callback(err);
}
break;
}
default:
callback({
message: 'Unknown provider.',
Expand Down

0 comments on commit 1bdce04

Please sign in to comment.