AuthenticationMethodOIDCServiceApi.ts•7.48 kB
// TODO: better import syntax?
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
import {Configuration} from '../configuration';
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {canConsumeForm, isCodeInRange} from '../util';
import {SecurityAuthentication} from '../auth/auth';
import { AuthorizeURLResponse } from '../models/AuthorizeURLResponse';
import { CallbackResponse } from '../models/CallbackResponse';
/**
* no description
*/
export class AuthenticationMethodOIDCServiceApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param provider
* @param state
*/
public async oidcAuthorizeURL(provider: string, state?: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'provider' is not null or undefined
if (provider === null || provider === undefined) {
throw new RequiredError("AuthenticationMethodOIDCServiceApi", "oidcAuthorizeURL", "provider");
}
// Path Params
const localVarPath = '/auth/v1/method/oidc/{provider}/authorize'
.replace('{' + 'provider' + '}', encodeURIComponent(String(provider)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (state !== undefined) {
requestContext.setQueryParam("state", ObjectSerializer.serialize(state, "string", ""));
}
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* @param provider
* @param code
* @param state
*/
public async oidcCallback(provider: string, code?: string, state?: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'provider' is not null or undefined
if (provider === null || provider === undefined) {
throw new RequiredError("AuthenticationMethodOIDCServiceApi", "oidcCallback", "provider");
}
// Path Params
const localVarPath = '/auth/v1/method/oidc/{provider}/callback'
.replace('{' + 'provider' + '}', encodeURIComponent(String(provider)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (code !== undefined) {
requestContext.setQueryParam("code", ObjectSerializer.serialize(code, "string", ""));
}
// Query Params
if (state !== undefined) {
requestContext.setQueryParam("state", ObjectSerializer.serialize(state, "string", ""));
}
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class AuthenticationMethodOIDCServiceApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to oidcAuthorizeURL
* @throws ApiException if the response code was not in [200, 299]
*/
public async oidcAuthorizeURLWithHttpInfo(response: ResponseContext): Promise<HttpInfo<AuthorizeURLResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: AuthorizeURLResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"AuthorizeURLResponse", ""
) as AuthorizeURLResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: AuthorizeURLResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"AuthorizeURLResponse", ""
) as AuthorizeURLResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to oidcCallback
* @throws ApiException if the response code was not in [200, 299]
*/
public async oidcCallbackWithHttpInfo(response: ResponseContext): Promise<HttpInfo<CallbackResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: CallbackResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"CallbackResponse", ""
) as CallbackResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: CallbackResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"CallbackResponse", ""
) as CallbackResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}