1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.fetchVerificationKeys = void 0;
|
7 | var util_1 = require("@sap-cloud-sdk/util");
|
8 | var axios_1 = __importDefault(require("axios"));
|
9 | var logger = (0, util_1.createLogger)({
|
10 | package: 'core',
|
11 | messageContext: 'xsuaa-service'
|
12 | });
|
13 | function fetchVerificationKeys(xsuaaUriOrCredentials, clientIdOrJku,
|
14 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
15 | clientSecret) {
|
16 |
|
17 | if (typeof xsuaaUriOrCredentials !== 'string') {
|
18 | if (!clientIdOrJku) {
|
19 | logger.warn('JKU field from the JWT not provided. Use xsuaaClient.url/token_keys as fallback. ' +
|
20 | 'This will not work for subscriber accounts created after 14th of April 2020.' +
|
21 | 'Please provide the right URL given by the field `jku` in the JWT header.');
|
22 | return executeFetchVerificationKeys("".concat(xsuaaUriOrCredentials.url, "/token_keys"));
|
23 | }
|
24 | return executeFetchVerificationKeys(clientIdOrJku);
|
25 | }
|
26 |
|
27 | return executeFetchVerificationKeys(xsuaaUriOrCredentials);
|
28 | }
|
29 | exports.fetchVerificationKeys = fetchVerificationKeys;
|
30 |
|
31 | function executeFetchVerificationKeys(url) {
|
32 | var config = {
|
33 | url: url,
|
34 | method: 'GET'
|
35 | };
|
36 | return axios_1.default
|
37 | .request(config)
|
38 | .then(function (resp) { return resp.data.keys.map(function (k) { return (0, util_1.renameKeys)(tokenKeyKeyMapping, k); }); })
|
39 | .catch(function (error) {
|
40 | throw new util_1.ErrorWithCause("Failed to fetch verification keys from XSUAA service instance \"".concat(url, "\"."), error);
|
41 | });
|
42 | }
|
43 | var tokenKeyKeyMapping = {
|
44 | kty: 'keyType',
|
45 | e: 'publicKeyExponent',
|
46 | use: 'use',
|
47 | kid: 'keyId',
|
48 | alg: 'algorithm',
|
49 | value: 'value',
|
50 | n: 'publicKeyModulus'
|
51 | };
|
52 |
|
\ | No newline at end of file |