1- 'use strict'
1+ import { InternalOAuthError , Strategy } from "passport-oauth2" ;
2+ import * as config from "../../config" ;
23
3- const { Strategy, InternalOAuthError } = require ( 'passport-oauth2' )
4- const config = require ( '../../config' )
5-
6- function parseProfile ( data ) {
4+ export function parseProfile ( data ) {
75 const username = extractProfileAttribute ( data , config . oauth2 . userProfileUsernameAttr )
86 const displayName = extractProfileAttribute ( data , config . oauth2 . userProfileDisplayNameAttr )
97 const email = extractProfileAttribute ( data , config . oauth2 . userProfileEmailAttr )
@@ -22,7 +20,7 @@ function parseProfile (data) {
2220 }
2321}
2422
25- function extractProfileAttribute ( data , path ) {
23+ export function extractProfileAttribute ( data , path ) {
2624 if ( ! data ) return undefined
2725 if ( typeof path !== 'string' ) return undefined
2826 // can handle stuff like `attrs[0].name`
@@ -41,7 +39,8 @@ function extractProfileAttribute (data, path) {
4139 return data
4240}
4341
44- class OAuth2CustomStrategy extends Strategy {
42+ export class OAuth2CustomStrategy extends Strategy {
43+ private _userProfileURL : any ;
4544 constructor ( options , verify ) {
4645 options . customHeaders = options . customHeaders || { }
4746 super ( options , verify )
@@ -58,10 +57,10 @@ class OAuth2CustomStrategy extends Strategy {
5857
5958 let profile , json
6059 try {
61- json = JSON . parse ( body )
60+ json = JSON . parse ( body as any )
6261 profile = parseProfile ( json )
6362 } catch ( ex ) {
64- return done ( new InternalOAuthError ( 'Failed to parse user profile' + ex . toString ( ) ) )
63+ return done ( new InternalOAuthError ( 'Failed to parse user profile' + ex . toString ( ) , null ) )
6564 }
6665
6766 profile . provider = 'oauth2'
@@ -70,7 +69,3 @@ class OAuth2CustomStrategy extends Strategy {
7069 } )
7170 }
7271}
73-
74- exports . OAuth2CustomStrategy = OAuth2CustomStrategy
75- exports . parseProfile = parseProfile
76- exports . extractProfileAttribute = extractProfileAttribute
0 commit comments