/** * Paze Checkout APILib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, RequestOptions } from '../core.js'; import { ClientAssertionTypeEnum, clientAssertionTypeEnumSchema, } from '../models/clientAssertionTypeEnum.js'; import { GrantTypeEnum, grantTypeEnumSchema } from '../models/grantTypeEnum.js'; import { OAuthTokenResponse, oAuthTokenResponseSchema, } from '../models/oAuthTokenResponse.js'; import { string } from '../schema.js'; import { BaseController } from './baseController.js'; import { SimpleError } from '../errors/simpleError.js'; export class IdentityController extends BaseController { /** * Creates an OAuth access token using a JWT client assertion as defined in RFC7523. The token is valid * for 30 minutes. * * * @param grantType * @param clientAssertion JWT client assertion * @param clientAssertionType * @return Response from the API call */ async createOAuthToken( grantType: GrantTypeEnum, clientAssertion: string, clientAssertionType: ClientAssertionTypeEnum, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST', '/token'); const mapped = req.prepareArgs({ grantType: [grantType, grantTypeEnumSchema], clientAssertion: [clientAssertion, string()], clientAssertionType: [clientAssertionType, clientAssertionTypeEnumSchema], }); req.header('Content-Type', 'application/x-www-form-urlencoded'); req.form({ grant_type: mapped.grantType, client_assertion: mapped.clientAssertion, client_assertion_type: mapped.clientAssertionType, }); req.throwOn(400, SimpleError, 'Invalid grant'); req.throwOn(401, SimpleError, 'Unauthorized client assertion'); req.authenticate([{ oAuth2: true }]); return req.callAsJson(oAuthTokenResponseSchema, requestOptions); } }