mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 18:08:11 +00:00 
			
		
		
		
	Add LinkedIn auth provider (#7490)
* Add LinkedIn auth provider Signed-off-by: Khalid Elshafie <abolkog@gmail.com>
This commit is contained in:
		
							parent
							
								
									6dce6e362f
								
							
						
					
					
						commit
						3e23646f1b
					
				| @ -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. | Your configuration is done. | ||||||
|  | |||||||
| @ -94,6 +94,14 @@ module.exports = async () => { | |||||||
|       callback: `${strapi.config.server.url}/auth/twitch/callback`, |       callback: `${strapi.config.server.url}/auth/twitch/callback`, | ||||||
|       scope: ['user:read:email'], |       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' })) || {}; |   const prevGrantConfig = (await pluginStore.get({ key: 'grant' })) || {}; | ||||||
|   // store grant auth config to db
 |   // store grant auth config to db
 | ||||||
|  | |||||||
| @ -386,6 +386,69 @@ const getProfile = async (provider, query, callback) => { | |||||||
|         }); |         }); | ||||||
|       break; |       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: |     default: | ||||||
|       callback({ |       callback({ | ||||||
|         message: 'Unknown provider.', |         message: 'Unknown provider.', | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Khalid Elshafie
						Khalid Elshafie