supertokens.init({ framework: "express", supertokens: { // These are the connection details of the app you created on supertokens.com connectionURI: "XXX", apiKey: "XXX", }, appInfo: { // learn more about this on https://supertokens.com/docs/session/appinfo appName: "XX", apiDomain: "XXX", websiteDomain: "XX", apiBasePath: "XX", websiteBasePath: "XXX" }, recipeList: [ ThirdParty.init({ signInAndUpFeature: { providers: [ { id: "linkedin", get: (redirectURI, authCodeFromRequest) => { return { accessTokenAPI: { // this contains info about the token endpoint which exchanges the auth code with the access token and profile info. url: "https://www.linkedin.com/oauth/v2/accessToken", params: { // example post params client_id: "XX", client_secret: "XX", grant_type: "authorization_code", redirect_uri: redirectURI || "", code: authCodeFromRequest || "", //... } }, authorisationRedirect: { // this contains info about forming the authorisation redirect URL without the state params and without the redirect_uri param url: "https://www.linkedin.com/oauth/v2/authorization", params: { client_id: "XX", scope: "r_emailaddress r_liteprofile", response_type: "code", //... } }, getClientId: () => { return "78rvglw44zfmkz"; }, getProfileInfo: async (accessTokenAPIResponse) => { var userEmailObj = { method: 'get', url: 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', headers: { 'Authorization': 'Bearer '+ accessTokenAPIResponse.access_token } }; var userProfileObj = { method: 'get', url: 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))', headers: { 'Authorization': 'Bearer '+ accessTokenAPIResponse.access_token } } try{ let userEmail = await axios(userEmailObj) let userProfile = await axios(userProfileObj) return { id: userProfile.data.id, email: { id: userEmail['data']['elements'][0]['handle~']['emailAddress'], isVerified: true }, }; } catch (e) { console.log(e) } } } }}, ], }, override: { apis: (originalImplementation) => { return { ...originalImplementation, signInUpPOST: async function (input) { if (originalImplementation.signInUpPOST === undefined) { throw Error("Should never come here"); } let response = await originalImplementation.signInUpPOST(input) if (response.status === "OK") { // In this example we are using Google as our provider let accessToken = response.authCodeResponse.access_token let userProfileObj = { method: 'get', url: 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))', headers: { 'Authorization': 'Bearer '+ accessToken } } let userProfile = await axios(userProfileObj) let userMetaData = { firstName: userProfile.data.firstName.localized.en_US, lastName: userProfile.data.lastName.localized.en_US, profilePicture: userProfile.data['profilePicture']['displayImage~']['elements'][3]['identifiers'][0]['identifier'], } await UserMetadata.updateUserMetadata(response.user.id, userMetaData); if(response.createdNewUser) { client.sendEmailWithTemplate({ "From": "accounts@param.ai", "To": response.user.email, "TemplateAlias": "welcome_email_text", "TemplateModel": { "product_name": "XX", "product_url": "XX", "person": { "first_name": userProfile.data.firstName.localized.en_US.split(" ")[0] }, "company_name": "FactEye Tech Labs Pvt Ltd", "company_address": "Gachibowli, Hyderabad, India", } }); } } return response; }, } } }, }), UserMetadata.init(), Session.init() // initializes session features ] });