data-and-reporting-sdk
Version:
Data And Reporting product consists of API's which provides details of transaction and invoice informations about shell cards. The Shell Card Transaction and Invoice API is REST-based and employs Basic authentication in Version 1 and Oauth authentication
48 lines • 2.47 kB
JavaScript
/**
* Shell Data & Reporting APIsLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuthAuthorizationController = void 0;
var tslib_1 = require("tslib");
var oAuthToken_js_1 = require("../models/oAuthToken.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var oAuthProviderError_js_1 = require("../errors/oAuthProviderError.js");
var OAuthAuthorizationController = /** @class */ (function (_super) {
tslib_1.__extends(OAuthAuthorizationController, _super);
function OAuthAuthorizationController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Create a new OAuth 2 token.
*
* @param authorization Authorization header in Basic auth format
* @param scope Requested scopes as a space-delimited list.
* @return Response from the API call
*/
OAuthAuthorizationController.prototype.requestToken = function (authorization, scope, fieldParameters, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST', '/v2/oauth/token');
req.baseUrl('OAuth Server');
mapped = req.prepareArgs({
authorization: [authorization, (0, schema_js_1.string)()],
scope: [scope, (0, schema_js_1.optional)((0, schema_js_1.string)())],
});
req.header('Authorization', mapped.authorization);
req.form(tslib_1.__assign({ grant_type: 'client_credentials', scope: mapped.scope }, fieldParameters));
req.throwOn(400, oAuthProviderError_js_1.OAuthProviderError, 'OAuth 2 provider returned an error.');
req.throwOn(401, oAuthProviderError_js_1.OAuthProviderError, 'OAuth 2 provider says client authentication failed.');
req.authenticate(false);
return [2 /*return*/, req.callAsJson(oAuthToken_js_1.oAuthTokenSchema, requestOptions)];
});
});
};
return OAuthAuthorizationController;
}(baseController_js_1.BaseController));
exports.OAuthAuthorizationController = OAuthAuthorizationController;
//# sourceMappingURL=oAuthAuthorizationController.js.map
;