/* tslint:disable */
/* eslint-disable */
/**
*
* # Introduction The Rest API is the webservices that allow you to automatically manage the wallets and operations. Many DIRECTKIT functionalities are also available manually using the BACKOFFICE # Authentication This service strictly follow the chapter 4.4.2 "Access Token request" of the RFC 6749 "the Oauth2 2.0 Authorization Framework". This Api is consume by the client api, a restrict control on IP is applied.
The unique method exposed by this api allow customers to ask for a unique bearer access token. A bearer allow the customer to consume their api Rest without the need of sending their plain text login and password.
This method has these scenario:
- In case the bearer do not exist, the method create a new bearer.
- In case the bearer already exist, it return the actual bearer with the remaining time left.
- In case the bearer lifetime is over, this method create a new bearer and delete the previous one.
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import * as runtime from '../runtime';
import type {
Bearer,
ProblemDetails,
} from '../models';
import {
BearerFromJSON,
BearerToJSON,
ProblemDetailsFromJSON,
ProblemDetailsToJSON,
} from '../models';
export interface TokenRequest {
authorization: string;
grantType: string;
}
/**
*
*/
export class OAuth2Api extends runtime.BaseAPI {
/**
* Client credential grant use to request access token
*/
async tokenRaw(requestParameters: TokenRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> {
if (requestParameters.authorization === null || requestParameters.authorization === undefined) {
throw new runtime.RequiredError('authorization','Required parameter requestParameters.authorization was null or undefined when calling token.');
}
if (requestParameters.grantType === null || requestParameters.grantType === undefined) {
throw new runtime.RequiredError('grantType','Required parameter requestParameters.grantType was null or undefined when calling token.');
}
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
if (requestParameters.authorization !== undefined && requestParameters.authorization !== null) {
headerParameters['Authorization'] = String(requestParameters.authorization);
}
const consumes: runtime.Consume[] = [
{ contentType: 'application/x-www-form-urlencoded' },
];
// @ts-ignore: canConsumeForm may be unused
const canConsumeForm = runtime.canConsumeForm(consumes);
let formParams: { append(param: string, value: any): any };
let useForm = false;
if (useForm) {
formParams = new FormData();
} else {
formParams = new URLSearchParams();
}
if (requestParameters.grantType !== undefined) {
formParams.append('Grant_type', requestParameters.grantType as any);
}
const response = await this.request({
path: `/api/v1/oauth/token`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: formParams,
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => BearerFromJSON(jsonValue));
}
/**
* Client credential grant use to request access token
*/
async token(requestParameters: TokenRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise {
const response = await this.tokenRaw(requestParameters, initOverrides);
return await response.value();
}
}