mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
Fix to retrieve oidcEmailAttribute from tokenSet.claims() that converts tie idToken in array, if the oidcEmailAttribute is not found in standard userInfo
This commit is contained in:
parent
e410e21363
commit
9290990ef9
1 changed files with 21 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
const { email } = require('sails-hook-orm/constants/deprecated-validations.list');
|
||||
module.exports = {
|
||||
inputs: {
|
||||
code: {
|
||||
|
@ -22,8 +23,9 @@ module.exports = {
|
|||
const client = sails.hooks.oidc.getClient();
|
||||
|
||||
let userInfo;
|
||||
let tokenSet;
|
||||
try {
|
||||
const tokenSet = await client.callback(
|
||||
tokenSet = await client.callback(
|
||||
sails.config.custom.oidcRedirectUri,
|
||||
{
|
||||
iss: sails.config.custom.oidcIssuer,
|
||||
|
@ -33,7 +35,9 @@ module.exports = {
|
|||
nonce: inputs.nonce,
|
||||
},
|
||||
);
|
||||
|
||||
userInfo = await client.userinfo(tokenSet);
|
||||
|
||||
} catch (e) {
|
||||
if (
|
||||
e instanceof SyntaxError &&
|
||||
|
@ -47,10 +51,21 @@ module.exports = {
|
|||
throw 'invalidCodeOrNonce';
|
||||
}
|
||||
|
||||
if (
|
||||
!userInfo[sails.config.custom.oidcEmailAttribute] ||
|
||||
!userInfo[sails.config.custom.oidcNameAttribute]
|
||||
) {
|
||||
/*
|
||||
Try to take the emailAttribute (configured in parameter OIDC_EMAIL_ATTRIBUTE in .env)
|
||||
from standard OIDC userInfo attribute
|
||||
*/
|
||||
let emailAttribute = userInfo[sails.config.custom.oidcEmailAttribute];
|
||||
|
||||
/*
|
||||
If undefined, I try to retrieve the token from the tokenSet.claims() that converts the
|
||||
id_token in a token_array
|
||||
*/
|
||||
if(!emailAttribute) {
|
||||
emailAttribute = tokenSet.claims()[sails.config.custom.oidcEmailAttribute];
|
||||
}
|
||||
|
||||
if (!emailAttribute || !userInfo[sails.config.custom.oidcNameAttribute]) {
|
||||
throw 'missingValues';
|
||||
}
|
||||
|
||||
|
@ -68,7 +83,7 @@ module.exports = {
|
|||
|
||||
const values = {
|
||||
isAdmin,
|
||||
email: userInfo[sails.config.custom.oidcEmailAttribute],
|
||||
email: emailAttribute,
|
||||
isSso: true,
|
||||
name: userInfo[sails.config.custom.oidcNameAttribute],
|
||||
subscribeToOwnCards: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue