1
1
import { InternalOAuthError , Strategy } from "passport-oauth2" ;
2
2
import config from "../../config" ;
3
3
4
- export function parseProfile ( data ) {
4
+ export function parseProfile ( data ) {
5
5
const username = extractProfileAttribute ( data , config . oauth2 . userProfileUsernameAttr )
6
6
const displayName = extractProfileAttribute ( data , config . oauth2 . userProfileDisplayNameAttr )
7
7
const email = extractProfileAttribute ( data , config . oauth2 . userProfileEmailAttr )
@@ -20,7 +20,7 @@ export function parseProfile (data) {
20
20
}
21
21
}
22
22
23
- export function extractProfileAttribute ( data , path ) {
23
+ export function extractProfileAttribute ( data , path ) {
24
24
if ( ! data ) return undefined
25
25
if ( typeof path !== 'string' ) return undefined
26
26
// can handle stuff like `attrs[0].name`
@@ -41,15 +41,16 @@ export function extractProfileAttribute (data, path) {
41
41
42
42
export class OAuth2CustomStrategy extends Strategy {
43
43
private _userProfileURL : any ;
44
- constructor ( options , verify ) {
44
+
45
+ constructor ( options , verify ) {
45
46
options . customHeaders = options . customHeaders || { }
46
47
super ( options , verify )
47
48
this . name = 'oauth2'
48
49
this . _userProfileURL = options . userProfileURL
49
50
this . _oauth2 . useAuthorizationHeaderforGET ( true )
50
51
}
51
52
52
- userProfile ( accessToken , done ) {
53
+ userProfile ( accessToken , done ) {
53
54
this . _oauth2 . get ( this . _userProfileURL , accessToken , function ( err , body , res ) {
54
55
if ( err ) {
55
56
return done ( new InternalOAuthError ( 'Failed to fetch user profile' , err ) )
0 commit comments