@sap/xssec
Version:
XS Advanced Container Security API for node.js
79 lines (62 loc) • 1.88 kB
JavaScript
const Token = require("./Token");
class XsuaaToken extends Token {
/**
* @param {string|null} jwt
* @param {object} [content] - optional parsed header and payload
* @param {import('../util/Types').JwtHeader & { [key: string]: any }} [content.header] - parsed header
* @param {import('../util/Types').JwtPayload & import('../util/Types').XsuaaJwtPayload & { [key: string]: any }} [content.payload] - parsed payload
*/
constructor(jwt, { header, payload } = {}) {
super(jwt, { header, payload });
}
get azAttributes() {
return this.payload.az_attr;
}
get extAttributes() {
return this.payload.ext_attr;
}
get logonName() {
return this.payload.user_name;
}
/**
* @returns {string[]} the scopes of the token
*/
get scopes() {
return this.payload.scope ?? [];
}
get serviceInstanceId() {
return this.payload.ext_attr?.serviceinstanceid;
}
get subAccountId() {
return this.payload.ext_attr?.subaccountid || this.zid;
}
get userId() {
return super.userId || this.payload.sub;
}
get xsUserAttributes() {
return this.payload.ext_cxt?.['xs.user.attributes'] ?? this.payload['xs.user.attributes'];
}
get xsSystemAttributes() {
return this.payload.ext_cxt?.['xs.system.attributes'] ?? this.payload['xs.system.attributes'];
}
/**
* @returns {string} The zone id of the token.
*/
get zid() {
return this.payload.zid;
}
getXsUserAttribute(name) {
return this.xsUserAttributes?.[name];
}
// Methods for backward-compatibility
getAppTID() {
return this.zid;
}
getCustomIssuer() {
return this.issuer;
}
getZoneId() {
return this.zid;
}
}
module.exports = XsuaaToken;