UNPKG

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

33 lines 1.53 kB
/** * Shell Data & Reporting APIsLib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { oAuthTokenSchema } from '../models/oAuthToken.js'; import { optional, string } from '../schema.js'; import { BaseController } from './baseController.js'; import { OAuthProviderError } from '../errors/oAuthProviderError.js'; export class OAuthAuthorizationController extends BaseController { /** * 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 */ async requestToken(authorization, scope, fieldParameters, requestOptions) { const req = this.createRequest('POST', '/v2/oauth/token'); req.baseUrl('OAuth Server'); const mapped = req.prepareArgs({ authorization: [authorization, string()], scope: [scope, optional(string())], }); req.header('Authorization', mapped.authorization); req.form(Object.assign({ grant_type: 'client_credentials', scope: mapped.scope }, fieldParameters)); req.throwOn(400, OAuthProviderError, 'OAuth 2 provider returned an error.'); req.throwOn(401, OAuthProviderError, 'OAuth 2 provider says client authentication failed.'); req.authenticate(false); return req.callAsJson(oAuthTokenSchema, requestOptions); } } //# sourceMappingURL=oAuthAuthorizationController.js.map