775ac7b58c
you must login with an BTP account in order to see the app
52 lines
1.2 KiB
JavaScript
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;
|