Skip to content

Commit

Permalink
set saml configuration mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
patkub committed Jul 21, 2024
1 parent 72502ad commit e77358f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NPM: https://www.npmjs.com/package/auth0-rule-as-action
- `callback` method with success and error
- ID and Access token claims
- `context.idToken["claim"] = "value"` becomes `api.idToken.setCustomClaim(claim, value)`
- SAML configuration mappings

## Example

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth0-rule-as-action",
"version": "0.1.21",
"version": "0.1.22",
"description": "Run an Auth0 Rule as an Action",
"main": "dist/RuleToAction.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/convert.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ function handleContextMutations(newContext) {

// set ID and Access token claims that changed between newContext and oldContext
for (const [claim, value] of Object.entries(newContext.idToken)) {
if (newContext.idToken[claim] && newContext.idToken[claim] != oldContext.idToken[claim]) {
if (value && value != oldContext.idToken[claim]) {
api.idToken.setCustomClaim(claim, value)
}
}
for (const [claim, value] of Object.entries(newContext.accessToken)) {
if (newContext.accessToken[claim] && newContext.accessToken[claim] != oldContext.accessToken[claim]) {
if (value && value != oldContext.accessToken[claim]) {
api.accessToken.setCustomClaim(claim, value)
}
}

// set SAML configuration mappings
for (const [claim, value] of Object.entries(newContext.samlConfiguration?.mappings)) {
if (value && value != oldContext.samlConfiguration?.mappings[claim]) {
api.samlResponse.setAttribute(claim, value);
}
}
}

export {
Expand Down
1 change: 1 addition & 0 deletions src/mapEventToContext.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function MapEventToContext(event) {
const context = {
accessToken: {},
idToken: {},
samlConfiguration: {},
multifactor: {},
sessionID: null
};
Expand Down

0 comments on commit e77358f

Please sign in to comment.