SAP-BTP-Spielwiese/app1/node_modules/@sap/xssec/lib/tokenexchanger.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

37 lines
No EOL
1.1 KiB
JavaScript

'use strict';
const CONFIG = require('./xssec.config');
const requests = require('./requests');
const TokenInfo = require('./tokeninfo');
function TokenExchanger(serviceCredentials, forceNoExchange) {
this.prepareToken = function(accessToken, cb) {
var token = new TokenInfo(accessToken);
if (token.isValid() && !token.isTokenIssuedByXSUAA() && !(forceNoExchange === true)) {
return exchangeIASToken(token, accessToken, cb);
} else {
cb(null, token);
}
}
function exchangeIASToken(ias_token, accessToken, cb) {
if(CONFIG.IAS_XSUAA_XCHANGE_ENABLED !== true) {
return cb(new Error("Unexpected TokenType"));
}
//try to convert (IAS) token to an XSUAA token using the ZoneId from the token
requests.requestUserToken(accessToken, serviceCredentials, null, null, null, ias_token.getAppTID(), function(err, xsuaaToken, json) {
if(err) {
cb(err);
} else {
var xtoken = new TokenInfo(xsuaaToken);
cb(null, xtoken);
}
})
}
}
module.exports = TokenExchanger;