Created
January 9, 2022 12:49
-
-
Save BalachandraTejas/8e3c9474d559b3d42230139a2984ef57 to your computer and use it in GitHub Desktop.
backendConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword' | |
import SessionNode from 'supertokens-node/recipe/session' | |
import { appInfo } from './appInfo' | |
import {TypeInput} from 'supertokens-node/lib/build/types' | |
const axios = require('axios'); | |
export let backendConfig = () => { | |
return { | |
framework: 'express', | |
supertokens: { | |
// connectionURI: 'https://try.supertokens.io', | |
}, | |
appInfo, | |
recipeList: [ | |
ThirdPartyEmailPasswordNode.init({ | |
providers: [ | |
{ | |
id: "linkedin", | |
// : TypeProviderGetResponse | |
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: process.env.LINKEDIN_CLIENT_ID, | |
client_secret: process.env.LINKEDIN_CLIENT_SECRET, | |
grant_type: "authorization_code", | |
redirect_uri: redirectURI, // process.env.LINKEDIN_REDIRECT_URI | |
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: process.env.LINKEDIN_CLIENT_ID, | |
scope: "r_liteprofile r_emailaddress", | |
response_type: "code", | |
// client_secret: process.env.LINKEDIN_CLIENT_SECRET, | |
redirect_uri: "http://localhost:3000/auth/callback/linkedin", | |
} | |
}, | |
getClientId: () => { | |
return process.env.LINKEDIN_CLIENT_ID; | |
}, | |
getProfileInfo: async (accessTokenAPIResponse) => { | |
/* accessTokenAPIResponse is the JSON response from the accessTokenAPI POST call. Using this, you need to return an object of the following type:*/ | |
let accessToken = accessTokenAPIResponse.access_token; | |
let authHeader = `Bearer ${accessToken}`; | |
let response = await axios({ | |
method: "get", | |
url: "https://api.linkedin.com/v2/me", | |
params: { | |
alt: "json", | |
}, | |
headers: { | |
Authorization: authHeader, | |
}, | |
}); | |
let userInfo = response.data; | |
let id = userInfo.id; | |
return { id } | |
} | |
} | |
} | |
} | |
], | |
}), | |
SessionNode.init(), | |
], | |
isInServerlessEnv: true, | |
} as TypeInput | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment