@@ -21,10 +21,11 @@ class OAuthCallbackError extends Error {
2121
2222 * @TODO Refactor to use promises and not callbacks
2323 */
24- export default async function oAuthCallback ( req , provider , csrfToken ) {
24+ export default async function oAuthCallback ( req , csrfToken ) {
2525 // The "user" object is specific to the Apple provider and is provided on first sign in
2626 // e.g. {"name":{"firstName":"Johnny","lastName":"Appleseed"},"email":"[email protected] " } 2727 let { oauth_token, oauth_verifier, code, user, state } = req . query // eslint-disable-line camelcase
28+ const provider = req . options . providers [ req . options . provider ]
2829 const client = oAuthClient ( provider )
2930
3031 if ( provider . version ?. startsWith ( '2.' ) ) {
@@ -86,6 +87,8 @@ export default async function oAuthCallback (req, provider, csrfToken) {
8687 // Support services that use OpenID ID Tokens to encode profile data
8788 const profileData = decodeIdToken ( results . id_token )
8889
90+ profileData . idToken = results . id_token
91+
8992 return _getProfile ( error , profileData , accessToken , refreshToken , provider , user )
9093 } else {
9194 // Use custom get() method for oAuth2 flows
@@ -97,6 +100,7 @@ export default async function oAuthCallback (req, provider, csrfToken) {
97100 accessToken ,
98101 results ,
99102 async ( error , profileData ) => {
103+ profileData . idToken = results . id_token
100104 result = await _getProfile ( error , profileData , accessToken , refreshToken , provider )
101105 }
102106 )
@@ -122,6 +126,7 @@ export default async function oAuthCallback (req, provider, csrfToken) {
122126 accessToken ,
123127 refreshToken ,
124128 async ( error , profileData ) => {
129+ profileData . idToken = results . id_token
125130 result = await _getProfile ( error , profileData , accessToken , refreshToken , provider )
126131 }
127132 )
@@ -135,7 +140,7 @@ export default async function oAuthCallback (req, provider, csrfToken) {
135140 * //6/30/2020 @geraldnolan added userData parameter to attach additional data to the profileData object
136141 * Returns profile, raw profile and auth provider details
137142 */
138- async function _getProfile ( error , profileData , accessToken , refreshToken , provider , userData ) {
143+ async function _getProfile ( error , profileData , accessToken , refreshToken , provider , userData , idToken ) {
139144 if ( error ) {
140145 logger . error ( 'OAUTH_GET_PROFILE_ERROR' , error )
141146 throw new OAuthCallbackError ( error )
@@ -152,6 +157,8 @@ async function _getProfile (error, profileData, accessToken, refreshToken, provi
152157 profileData . user = userData
153158 }
154159
160+ profileData . idToken = idToken
161+
155162 logger . debug ( 'PROFILE_DATA' , profileData )
156163
157164 const profile = await provider . profile ( profileData )
0 commit comments