-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserApi.ts
More file actions
183 lines (148 loc) · 8.01 KB
/
UserApi.ts
File metadata and controls
183 lines (148 loc) · 8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// 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 { AuthCodeResponse } from '../models/AuthCodeResponse';
import { Exception } from '../models/Exception';
import { UserSession } from '../models/UserSession';
/**
* no description
*/
export class UserApiRequestFactory extends BaseAPIRequestFactory {
/**
* @param redirectUri The URI to which the identity provider should redirect after successful authentication.
* @param authCodeResponse
*/
public async authHandler(redirectUri: string, authCodeResponse: AuthCodeResponse, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'redirectUri' is not null or undefined
if (redirectUri === null || redirectUri === undefined) {
throw new RequiredError("UserApi", "authHandler", "redirectUri");
}
// verify required parameter 'authCodeResponse' is not null or undefined
if (authCodeResponse === null || authCodeResponse === undefined) {
throw new RequiredError("UserApi", "authHandler", "authCodeResponse");
}
// Path Params
const localVarPath = '/auth/accessTokenLogin';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (redirectUri !== undefined) {
requestContext.setQueryParam("redirectUri", ObjectSerializer.serialize(redirectUri, "string", "uri"));
}
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(authCodeResponse, "AuthCodeResponse", ""),
contentType
);
requestContext.setBody(serializedBody);
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* Generates a URL for initiating the OIDC code flow, which the frontend can use to redirect the user to the identity provider\'s login page.
* @param redirectUri The URI to which the identity provider should redirect after successful authentication.
*/
public async authRequestUrlHandler(redirectUri: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'redirectUri' is not null or undefined
if (redirectUri === null || redirectUri === undefined) {
throw new RequiredError("UserApi", "authRequestUrlHandler", "redirectUri");
}
// Path Params
const localVarPath = '/auth/authenticationRequestUrl';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params
if (redirectUri !== undefined) {
requestContext.setQueryParam("redirectUri", ObjectSerializer.serialize(redirectUri, "string", "uri"));
}
const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class UserApiResponseProcessor {
/**
* 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 authHandler
* @throws ApiException if the response code was not in [200, 299]
*/
public async authHandlerWithHttpInfo(response: ResponseContext): Promise<HttpInfo<UserSession >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: UserSession = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"UserSession", ""
) as UserSession;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body: Exception = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Exception", ""
) as Exception;
throw new ApiException<Exception>(response.httpStatusCode, "A server error occurred.", body, response.headers);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: UserSession = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"UserSession", ""
) as UserSession;
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 authRequestUrlHandler
* @throws ApiException if the response code was not in [200, 299]
*/
public async authRequestUrlHandlerWithHttpInfo(response: ResponseContext): Promise<HttpInfo<string >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: string = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"string", "uri"
) as string;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body: Exception = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"Exception", "uri"
) as Exception;
throw new ApiException<Exception>(response.httpStatusCode, "A server error occurred.", body, response.headers);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: string = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"string", "uri"
) as string;
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);
}
}