UNPKG

@foal/social

Version:

Social authentication for FoalTS

45 lines (44 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LinkedInProvider = void 0; // std const url_1 = require("url"); // FoalTS const abstract_provider_service_1 = require("./abstract-provider.service"); const user_info_error_1 = require("./user-info.error"); /** * LinkedIn social provider. * * @export * @class LinkedInProvider * @extends {AbstractProvider<never, LinkedInUserInfoParams>} */ class LinkedInProvider extends abstract_provider_service_1.AbstractProvider { configPaths = { clientId: 'settings.social.linkedin.clientId', clientSecret: 'settings.social.linkedin.clientSecret', redirectUri: 'settings.social.linkedin.redirectUri', }; authEndpoint = 'https://www.linkedin.com/oauth/v2/authorization'; tokenEndpoint = 'https://www.linkedin.com/oauth/v2/accessToken'; userInfoEndpoint = 'https://api.linkedin.com/v2/me'; defaultScopes = ['r_liteprofile']; async getUserInfoFromTokens(tokens, params = {}) { const url = new url_1.URL(this.userInfoEndpoint); if (params.projection) { url.searchParams.set('projection', params.projection); } if (params.fields) { url.searchParams.set('fields', params.fields.join(',')); } const response = await fetch(url.href, { headers: { Authorization: `Bearer ${tokens.access_token}` } }); const body = await response.json(); if (!response.ok) { throw new user_info_error_1.UserInfoError(body); } return body; } } exports.LinkedInProvider = LinkedInProvider;