1
- 'use strict'
1
+ import { InternalOAuthError , Strategy } from "passport-oauth2" ;
2
+ import * as config from "../../config" ;
2
3
3
- const { Strategy, InternalOAuthError } = require ( 'passport-oauth2' )
4
- const config = require ( '../../config' )
5
-
6
- function parseProfile ( data ) {
4
+ export function parseProfile ( data ) {
7
5
const username = extractProfileAttribute ( data , config . oauth2 . userProfileUsernameAttr )
8
6
const displayName = extractProfileAttribute ( data , config . oauth2 . userProfileDisplayNameAttr )
9
7
const email = extractProfileAttribute ( data , config . oauth2 . userProfileEmailAttr )
@@ -22,7 +20,7 @@ function parseProfile (data) {
22
20
}
23
21
}
24
22
25
- function extractProfileAttribute ( data , path ) {
23
+ export function extractProfileAttribute ( data , path ) {
26
24
if ( ! data ) return undefined
27
25
if ( typeof path !== 'string' ) return undefined
28
26
// can handle stuff like `attrs[0].name`
@@ -41,7 +39,8 @@ function extractProfileAttribute (data, path) {
41
39
return data
42
40
}
43
41
44
- class OAuth2CustomStrategy extends Strategy {
42
+ export class OAuth2CustomStrategy extends Strategy {
43
+ private _userProfileURL : any ;
45
44
constructor ( options , verify ) {
46
45
options . customHeaders = options . customHeaders || { }
47
46
super ( options , verify )
@@ -58,10 +57,10 @@ class OAuth2CustomStrategy extends Strategy {
58
57
59
58
let profile , json
60
59
try {
61
- json = JSON . parse ( body )
60
+ json = JSON . parse ( body as any )
62
61
profile = parseProfile ( json )
63
62
} 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 ) )
65
64
}
66
65
67
66
profile . provider = 'oauth2'
@@ -70,7 +69,3 @@ class OAuth2CustomStrategy extends Strategy {
70
69
} )
71
70
}
72
71
}
73
-
74
- exports . OAuth2CustomStrategy = OAuth2CustomStrategy
75
- exports . parseProfile = parseProfile
76
- exports . extractProfileAttribute = extractProfileAttribute
0 commit comments