Skip to content

Commit a979e04

Browse files
committed
feat: forward id_token to jwt and signIn callbacks (#1024)
1 parent 2205cfa commit a979e04

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/server/lib/oauth/callback.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/server/routes/callback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default async function callback (req, res) {
3131

3232
if (type === 'oauth') {
3333
try {
34-
const { profile, account, OAuthProfile } = await oAuthCallback(req, provider, csrfToken)
34+
const { profile, account, OAuthProfile } = await oAuthCallback(req, csrfToken)
3535
try {
3636
// Make it easier to debug when adding a new provider
3737
logger.debug('OAUTH_CALLBACK_RESPONSE', { profile, account, OAuthProfile })

0 commit comments

Comments
 (0)