UNPKG

@toruslabs/customauth

Version:

CustomAuth login with torus to get user private key

59 lines (55 loc) 1.8 kB
'use strict'; var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var httpHelpers = require('@toruslabs/http-helpers'); var deepmerge = require('deepmerge'); var AbstractLoginHandler = require('./AbstractLoginHandler.js'); class FacebookHandler extends AbstractLoginHandler { constructor(params) { super(params); _defineProperty(this, "RESPONSE_TYPE", "token"); _defineProperty(this, "SCOPE", "public_profile email"); this.setFinalUrl(); } setFinalUrl() { const finalUrl = new URL("https://www.facebook.com/v20.0/dialog/oauth"); const clonedParams = JSON.parse(JSON.stringify(this.params.jwtParams || {})); const finalJwtParams = deepmerge({ state: this.state, response_type: this.RESPONSE_TYPE, client_id: this.params.clientId, redirect_uri: this.params.redirect_uri, scope: this.SCOPE }, clonedParams); Object.keys(finalJwtParams).forEach(key => { const localKey = key; if (finalJwtParams[localKey]) finalUrl.searchParams.append(localKey, finalJwtParams[localKey]); }); this.finalURL = finalUrl; } async getUserInfo(params) { const { accessToken } = params; const userInfo = await httpHelpers.get("https://graph.facebook.com/me?fields=name,email,picture.type(large)", { headers: { Authorization: `Bearer ${accessToken}` } }); const { name = "", id, picture, email = "" } = userInfo; return { email, name, profileImage: picture.data.url || "", authConnectionId: this.params.authConnectionId, authConnection: this.params.authConnection, groupedAuthConnectionId: this.params.groupedAuthConnectionId, userId: id }; } } module.exports = FacebookHandler;