Skip to content

Commit

Permalink
IDAM-467 - updating the role to add claims
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Williams committed Nov 1, 2021
1 parent 0856e00 commit 2e74809
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
3 changes: 2 additions & 1 deletion custom-pages/clients/Test apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"client_id": "",
"client_secret": "",
"client_metadata": {
"authorise_uri": ""
"authorise_uri": "",
"role_issuers": ""
},
"jwt_configuration": {
"alg": "RS256",
Expand Down
22 changes: 6 additions & 16 deletions custom-pages/rules/Add roles to id token for nextjs client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function (user, context, callback) {
}

let idTokenClaims = context.idToken || {};
let accessTokenClaims = context.accessToken || {};

console.log("hitting the rule which to add roles to the id token - next js app found.");

Expand Down Expand Up @@ -52,35 +53,24 @@ function (user, context, callback) {
throw new Error(error);
}

console.log("response body received:");
console.log(body);
const claims = JSON.parse(body);

console.log("context:");
console.log(context);

var applicationMetadata = context.clientMetadata;

if (applicationMetadata && applicationMetadata.role_issuers){

const role_issuers = applicationMetadata.role_issuers.split(',');

console.log(Array.isArray(claims));

console.log("issuers:");
console.log(role_issuers);
const roleType = "http://identity.nice.org.uk/claims/role";

const rolesToAdd = claims.filter(role => role.type === "http://identity.nice.org.uk/claims/role" &&
const rolesToAdd = claims.filter(role => role.type === roleType &&
role_issuers.includes(role.issuer));

console.log("roles:");
console.log(rolesToAdd);

for (const roleToAdd of rolesToAdd) {
idTokenClaims[roleToAdd.type] = roleToAdd.value; //todo: figure this out.
}
idTokenClaims[roleType] = rolesToAdd.map(r => r.value);
accessTokenClaims[roleType] = rolesToAdd.map(r => r.value);

context.idToken = idTokenClaims;
context.accessToken = accessTokenClaims;
}

callback(null, user, context);
Expand Down

2 comments on commit 2e74809

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 1754 is now running

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 1754-IDAM-467-NiceorgFron outcome was SUCCESS
Summary: Tests passed: 65 Build time: 00:03:11

Please sign in to comment.