@sap-cloud-sdk/connectivity
Version:
SAP Cloud SDK for JavaScript connectivity
36 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeOrMakeJwt = decodeOrMakeJwt;
exports.getTenantIdFromBinding = getTenantIdFromBinding;
const environment_accessor_1 = require("../environment-accessor");
const jwt_1 = require("./jwt");
/**
* This method either decodes the given JWT or tries to retrieve the tenant from a service binding (XSUAA, IAS or destination) as `zid`.
* @param options - Options passed to register the destination containing the JWT.
* @returns The decoded JWT or a dummy JWT containing the tenant identifier (zid).
* @internal
*/
function decodeOrMakeJwt(jwt) {
if (jwt) {
const decodedJwt = typeof jwt === 'string' ? (0, jwt_1.decodeJwt)(jwt) : jwt;
if ((0, jwt_1.getTenantId)(decodedJwt)) {
return decodedJwt;
}
}
const providerTenantId = getTenantIdFromBinding();
// This is returning a JWT with an XSUAA style zid.
// It might make sense to check whether the binding was IAS and then rather return app_tid, as it would be in a IAS token.
if (providerTenantId) {
return { zid: providerTenantId };
}
}
/**
* @internal
* @returns The tenant identifier from the XSUAA, identity or destination service binding.
*/
function getTenantIdFromBinding() {
return ((0, environment_accessor_1.getServiceCredentials)('xsuaa')?.tenantid ||
(0, environment_accessor_1.getServiceCredentials)('identity')?.app_tid ||
(0, environment_accessor_1.getServiceCredentials)('destination')?.tenantid);
}
//# sourceMappingURL=binding.js.map