Skip to content

Commit

Permalink
use email from user info
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano committed Apr 30, 2024
1 parent 1d48de1 commit 0e807e8
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/oidcAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,31 @@ module.exports.finishAuth = async (req) => {
return { error: "L'identification a échoué. Entrez votre adresse mail ci-dessous pour recommencer." }
}

const tokenSet = await client.callback(
config.HOSTNAME_WITH_PROTOCOL + urlCallback,
params,
{
state: request.state,
nonce: request.nonce
// todo code_verifier: req.session.code_verifier
}
)
const claims = tokenSet.claims()
console.log(`CLAIMS : ${JSON.stringify(claims)}`)
const userinfo = await client.userinfo(tokenSet)
console.log(`USERINFO : ${JSON.stringify(userinfo)}`)
let tokenSet
try {
tokenSet = await client.callback(
config.HOSTNAME_WITH_PROTOCOL + urlCallback,
params,
{
state: request.state,
nonce: request.nonce
// todo code_verifier: req.session.code_verifier
}
)
} catch(error){
console.error("error when requesting token from OIDC", error)
return { error: "L'identification a échoué. Entrez votre adresse mail ci-dessous pour recommencer." }
}

let userinfo
try {
userinfo = await client.userinfo(tokenSet)
} catch(error){
console.error("error when requesting userinfo from OIDC", error)
return { error: "L'identification a échoué. Entrez votre adresse mail ci-dessous pour recommencer." }
}
const email = userinfo.email

const email = claims.preferred_username

return {
email,
durationInMinutes: request.durationInMinutes,
Expand Down

0 comments on commit 0e807e8

Please sign in to comment.