SAP-BTP-Spielwiese/app1/node_modules/@sap/xssec/lib/service/XsuaaService.js
Markus Rettig 775ac7b58c completed step 3 from the tutorial
you must login with an BTP account in order to see the app
2024-02-08 16:13:36 +01:00

52 lines
1.2 KiB
JavaScript

'use strict';
const requests = require('../requests');
const PROTOCOL = "https://";
class XsuaaService {
#url;
#jku // JWKS URL
#zid; // optional zone id
// immutable public fields
get url() { return this.#url; }
get jku() { return this.#jku; }
get zid() { return this.#zid; }
constructor(uaaDomain, zid) {
if (uaaDomain === undefined) {
throw new Error("XsuaaService requires a uaaDomain to fetch JWKS from.");
}
this.#url = uaaDomain.startsWith(PROTOCOL) ? uaaDomain : `${PROTOCOL}${uaaDomain}`;
this.#zid = zid;
this.#jku = `${this.url}/token_keys`;
}
async fetchJwks() {
return new Promise((res, rej) => {
try {
requests.fetchKeyFromXSUAA(this.jku, this.zid, null, function (err, json) {
if (err) {
return rej(err);
}
return res(json.keys);
});
} catch (e) {
return rej(e);
}
});
}
toJSON() {
return {
...this,
url: this.url,
zid: this.zid
}
}
}
module.exports = XsuaaService;