Last active
May 20, 2021 20:56
-
-
Save timcappalli/af55ee6ee5d2ae3f527f47e581178596 to your computer and use it in GitHub Desktop.
SSE Event Subject Processing Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const COMPLEX_SUBJECTS = ['user', 'device', 'session', 'application', 'tenant', 'org_unit'] | |
let secEventToken = { | |
iss: "https://idp.example.com/123456789/", | |
jti: "24c63fb56e5a2d77a6b512616ca9fa24", | |
iat: 1615305159, | |
aud: "https://sp.example.com/caep", | |
events: { | |
"https://schemas.openid.net/secevent/caep/event-type/session-revoked": { | |
subject: { | |
session: { | |
format: "opaque", | |
sub: "dMTlD|1600802906337.16|16008.16" | |
}, | |
user: { | |
format: "iss_sub", | |
iss: "https://idp.example.com/123456789/", | |
sub: "dMTlD|1600802906337.16|16008.16" | |
}, | |
tenant: { | |
format: "opaque", | |
id: "123456789" | |
} | |
}, | |
initiating_entity: "policy", | |
event_timestamp: 1615304991643 | |
} | |
} | |
} | |
function objectKeysInArray(obj, arr) { | |
for (const str of Object.keys(obj)) { | |
if (arr.includes(str)) { | |
continue; | |
} else { | |
return false; | |
} | |
} | |
return true; | |
} | |
if (Object.values(secEventToken.events)[0].subject.format) { | |
// process as standalone subject identifier | |
console.log('process as standalone subject identifier') | |
} else if (objectKeysInArray(Object.values(secEventToken.events)[0].subject, COMPLEX_SUBJECTS)) { | |
// process as complex subject | |
console.log('process as complex subject') | |
} else { | |
// invalid subject | |
console.log('invalid subject') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment