@typespec/http 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/src/content-types.d.ts +15 -0
- package/dist/src/content-types.d.ts.map +1 -0
- package/dist/src/content-types.js +42 -0
- package/dist/src/content-types.js.map +1 -0
- package/dist/src/decorators.d.ts +82 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/decorators.js +513 -0
- package/dist/src/decorators.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +294 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +121 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/metadata.d.ts +129 -0
- package/dist/src/metadata.d.ts.map +1 -0
- package/dist/src/metadata.js +323 -0
- package/dist/src/metadata.js.map +1 -0
- package/dist/src/operations.d.ts +31 -0
- package/dist/src/operations.d.ts.map +1 -0
- package/dist/src/operations.js +162 -0
- package/dist/src/operations.js.map +1 -0
- package/dist/src/parameters.d.ts +4 -0
- package/dist/src/parameters.d.ts.map +1 -0
- package/dist/src/parameters.js +142 -0
- package/dist/src/parameters.js.map +1 -0
- package/dist/src/responses.d.ts +7 -0
- package/dist/src/responses.d.ts.map +1 -0
- package/dist/src/responses.js +186 -0
- package/dist/src/responses.js.map +1 -0
- package/dist/src/route.d.ts +23 -0
- package/dist/src/route.d.ts.map +1 -0
- package/dist/src/route.js +149 -0
- package/dist/src/route.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/types.d.ts +254 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +8 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +11 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validate.d.ts +3 -0
- package/dist/src/validate.d.ts.map +1 -0
- package/dist/src/validate.js +9 -0
- package/dist/src/validate.js.map +1 -0
- package/lib/auth.tsp +185 -0
- package/lib/http-decorators.tsp +206 -0
- package/lib/http.tsp +57 -0
- package/package.json +72 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { DiagnosticResult, Interface, ListOperationOptions, ModelProperty, Namespace, Operation, Program, Type } from "@typespec/compiler";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use `HttpOperation`. To remove in November 2022 release.
|
|
4
|
+
*/
|
|
5
|
+
export type OperationDetails = HttpOperation;
|
|
6
|
+
export type HttpVerb = "get" | "put" | "post" | "patch" | "delete" | "head";
|
|
7
|
+
export interface ServiceAuthentication {
|
|
8
|
+
/**
|
|
9
|
+
* Either one of those options can be used independently to authenticate.
|
|
10
|
+
*/
|
|
11
|
+
options: AuthenticationOption[];
|
|
12
|
+
}
|
|
13
|
+
export interface AuthenticationOption {
|
|
14
|
+
/**
|
|
15
|
+
* For this authentication option all the given auth have to be used together.
|
|
16
|
+
*/
|
|
17
|
+
schemes: HttpAuth[];
|
|
18
|
+
}
|
|
19
|
+
export type HttpAuth = BasicAuth | BearerAuth | ApiKeyAuth<ApiKeyLocation, string> | Oauth2Auth<OAuth2Flow[]>;
|
|
20
|
+
export interface HttpAuthBase {
|
|
21
|
+
/**
|
|
22
|
+
* Id of the authentication scheme.
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional description.
|
|
27
|
+
*/
|
|
28
|
+
description?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Basic authentication is a simple authentication scheme built into the HTTP protocol.
|
|
32
|
+
* The client sends HTTP requests with the Authorization header that contains the word Basic word followed by a space and a base64-encoded string username:password.
|
|
33
|
+
* For example, to authorize as demo / p@55w0rd the client would send
|
|
34
|
+
* ```
|
|
35
|
+
* Authorization: Basic ZGVtbzpwQDU1dzByZA==
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface BasicAuth extends HttpAuthBase {
|
|
39
|
+
type: "http";
|
|
40
|
+
scheme: "basic";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens.
|
|
44
|
+
* The name “Bearer authentication” can be understood as “give access to the bearer of this token.” The bearer token is a cryptic string, usually generated by the server in response to a login request.
|
|
45
|
+
* The client must send this token in the Authorization header when making requests to protected resources:
|
|
46
|
+
* ```
|
|
47
|
+
* Authorization: Bearer <token>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface BearerAuth extends HttpAuthBase {
|
|
51
|
+
type: "http";
|
|
52
|
+
scheme: "bearer";
|
|
53
|
+
}
|
|
54
|
+
type ApiKeyLocation = "header" | "query" | "cookie";
|
|
55
|
+
/**
|
|
56
|
+
* An API key is a token that a client provides when making API calls. The key can be sent in the query string:
|
|
57
|
+
* ```
|
|
58
|
+
* GET /something?api_key=abcdef12345
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* or as a request header
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
* GET /something HTTP/1.1
|
|
65
|
+
* X-API-Key: abcdef12345
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* or as a cookie
|
|
69
|
+
*
|
|
70
|
+
* ```
|
|
71
|
+
* GET /something HTTP/1.1
|
|
72
|
+
* Cookie: X-API-KEY=abcdef12345
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface ApiKeyAuth<TLocation extends ApiKeyLocation, TName extends string> extends HttpAuthBase {
|
|
76
|
+
type: "apiKey";
|
|
77
|
+
in: TLocation;
|
|
78
|
+
name: TName;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* OAuth 2.0 is an authorization protocol that gives an API client limited access to user data on a web server.
|
|
82
|
+
* OAuth relies on authentication scenarios called flows, which allow the resource owner (user) to share the protected content from the resource server without sharing their credentials.
|
|
83
|
+
* For that purpose, an OAuth 2.0 server issues access tokens that the client applications can use to access protected resources on behalf of the resource owner.
|
|
84
|
+
* For more information about OAuth 2.0, see oauth.net and RFC 6749.
|
|
85
|
+
*/
|
|
86
|
+
export interface Oauth2Auth<TFlows extends OAuth2Flow[]> extends HttpAuthBase {
|
|
87
|
+
type: "oauth2";
|
|
88
|
+
flows: TFlows;
|
|
89
|
+
}
|
|
90
|
+
export type OAuth2Flow = AuthorizationCodeFlow | ImplicitFlow | PasswordFlow | ClientCredentialsFlow;
|
|
91
|
+
export type OAuth2FlowType = OAuth2Flow["type"];
|
|
92
|
+
/**
|
|
93
|
+
* Authorization Code flow
|
|
94
|
+
*/
|
|
95
|
+
export interface AuthorizationCodeFlow {
|
|
96
|
+
type: "authorizationCode";
|
|
97
|
+
authorizationUrl: string;
|
|
98
|
+
tokenUrl: string;
|
|
99
|
+
refreshUrl?: string;
|
|
100
|
+
scopes: OAuth2Scope[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Implicit flow
|
|
104
|
+
*/
|
|
105
|
+
export interface ImplicitFlow {
|
|
106
|
+
type: "implicit";
|
|
107
|
+
authorizationUrl: string;
|
|
108
|
+
refreshUrl?: string;
|
|
109
|
+
scopes: OAuth2Scope[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Resource Owner Password flow
|
|
113
|
+
*/
|
|
114
|
+
export interface PasswordFlow {
|
|
115
|
+
type: "password";
|
|
116
|
+
authorizationUrl: string;
|
|
117
|
+
refreshUrl?: string;
|
|
118
|
+
scopes: OAuth2Scope[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Client credentials flow
|
|
122
|
+
*/
|
|
123
|
+
export interface ClientCredentialsFlow {
|
|
124
|
+
type: "clientCredentials";
|
|
125
|
+
tokenUrl: string;
|
|
126
|
+
refreshUrl?: string;
|
|
127
|
+
scopes: OAuth2Scope[];
|
|
128
|
+
}
|
|
129
|
+
export interface OAuth2Scope {
|
|
130
|
+
value: string;
|
|
131
|
+
description?: string;
|
|
132
|
+
}
|
|
133
|
+
export type OperationContainer = Namespace | Interface;
|
|
134
|
+
export type OperationVerbSelector = (program: Program, operation: Operation) => HttpVerb | undefined;
|
|
135
|
+
export interface OperationParameterOptions {
|
|
136
|
+
verbSelector?: OperationVerbSelector;
|
|
137
|
+
}
|
|
138
|
+
export interface RouteOptions {
|
|
139
|
+
[prop: string]: any;
|
|
140
|
+
paramOptions?: OperationParameterOptions;
|
|
141
|
+
}
|
|
142
|
+
export interface RouteResolutionOptions extends RouteOptions {
|
|
143
|
+
listOptions?: ListOperationOptions;
|
|
144
|
+
}
|
|
145
|
+
export interface RouteProducerResult {
|
|
146
|
+
segments: string[];
|
|
147
|
+
parameters: HttpOperationParameters;
|
|
148
|
+
}
|
|
149
|
+
export type RouteProducer = (program: Program, operation: Operation, parentSegments: string[], overloadBase: HttpOperation | undefined, options: RouteOptions) => DiagnosticResult<RouteProducerResult>;
|
|
150
|
+
export interface HeaderFieldOptions {
|
|
151
|
+
type: "header";
|
|
152
|
+
name: string;
|
|
153
|
+
format?: "csv";
|
|
154
|
+
}
|
|
155
|
+
export interface QueryParameterOptions {
|
|
156
|
+
type: "query";
|
|
157
|
+
name: string;
|
|
158
|
+
format?: "multi" | "csv";
|
|
159
|
+
}
|
|
160
|
+
export interface PathParameterOptions {
|
|
161
|
+
type: "path";
|
|
162
|
+
name: string;
|
|
163
|
+
}
|
|
164
|
+
export type HttpOperationParameter = (HeaderFieldOptions | QueryParameterOptions | PathParameterOptions) & {
|
|
165
|
+
param: ModelProperty;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Represent the body information for an http request.
|
|
169
|
+
*
|
|
170
|
+
* @note the `type` must be a `Model` if the content type is multipart.
|
|
171
|
+
*/
|
|
172
|
+
export interface HttpOperationRequestBody extends HttpOperationBody {
|
|
173
|
+
/**
|
|
174
|
+
* If the body was explicitly set as a property. Correspond to the property with `@body`
|
|
175
|
+
*/
|
|
176
|
+
parameter?: ModelProperty;
|
|
177
|
+
}
|
|
178
|
+
export interface HttpOperationParameters {
|
|
179
|
+
parameters: HttpOperationParameter[];
|
|
180
|
+
body?: HttpOperationRequestBody;
|
|
181
|
+
/** @deprecated use @see body.type */
|
|
182
|
+
bodyType?: Type;
|
|
183
|
+
/** @deprecated use @see body.property */
|
|
184
|
+
bodyParameter?: ModelProperty;
|
|
185
|
+
}
|
|
186
|
+
export interface HttpService {
|
|
187
|
+
namespace: Namespace;
|
|
188
|
+
operations: HttpOperation[];
|
|
189
|
+
}
|
|
190
|
+
export interface HttpOperation {
|
|
191
|
+
/**
|
|
192
|
+
* Route path
|
|
193
|
+
*/
|
|
194
|
+
path: string;
|
|
195
|
+
/**
|
|
196
|
+
* Path segments
|
|
197
|
+
*/
|
|
198
|
+
pathSegments: string[];
|
|
199
|
+
/**
|
|
200
|
+
* Route verb.
|
|
201
|
+
*/
|
|
202
|
+
verb: HttpVerb;
|
|
203
|
+
/**
|
|
204
|
+
* Parent type being the interface, namespace or global namespace.
|
|
205
|
+
*/
|
|
206
|
+
container: OperationContainer;
|
|
207
|
+
/**
|
|
208
|
+
* Parameters.
|
|
209
|
+
*/
|
|
210
|
+
parameters: HttpOperationParameters;
|
|
211
|
+
/**
|
|
212
|
+
* Responses.
|
|
213
|
+
*/
|
|
214
|
+
responses: HttpOperationResponse[];
|
|
215
|
+
/**
|
|
216
|
+
* Operation type reference.
|
|
217
|
+
*/
|
|
218
|
+
operation: Operation;
|
|
219
|
+
/**
|
|
220
|
+
* Overload this operation
|
|
221
|
+
*/
|
|
222
|
+
overloading?: HttpOperation;
|
|
223
|
+
/**
|
|
224
|
+
* List of operations that overloads this one.
|
|
225
|
+
*/
|
|
226
|
+
overloads?: HttpOperation[];
|
|
227
|
+
}
|
|
228
|
+
export interface RoutePath {
|
|
229
|
+
path: string;
|
|
230
|
+
shared: boolean;
|
|
231
|
+
}
|
|
232
|
+
export type StatusCode = `${number}` | "*";
|
|
233
|
+
export interface HttpOperationResponse {
|
|
234
|
+
statusCode: StatusCode;
|
|
235
|
+
type: Type;
|
|
236
|
+
description?: string;
|
|
237
|
+
responses: HttpOperationResponseContent[];
|
|
238
|
+
}
|
|
239
|
+
export interface HttpOperationResponseContent {
|
|
240
|
+
headers?: Record<string, ModelProperty>;
|
|
241
|
+
body?: HttpOperationBody;
|
|
242
|
+
}
|
|
243
|
+
export interface HttpOperationBody {
|
|
244
|
+
/**
|
|
245
|
+
* Content types.
|
|
246
|
+
*/
|
|
247
|
+
contentTypes: string[];
|
|
248
|
+
/**
|
|
249
|
+
* Type of the operation body.
|
|
250
|
+
*/
|
|
251
|
+
type: Type;
|
|
252
|
+
}
|
|
253
|
+
export {};
|
|
254
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,SAAS,EACT,OAAO,EACP,IAAI,EACL,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAE7C,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,U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AEf;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;IACH,UAAU,EAAE,uBAAuB,CAAC;IAEpC;;OAEG;IACH,SAAS,EAAE,qBAAqB,EAAE,CAAC;IAEnC;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,UAAU,GAAG,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC;AAC3C,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,4BAA4B,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract params to be interpolated(Wrapped in '{' and '}'}) from a path/url.
|
|
3
|
+
* @param path Path/Url
|
|
4
|
+
*
|
|
5
|
+
* @example "foo/{name}/bar" -> ["name"]
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractParamsFromPath(path: string): string[];
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract params to be interpolated(Wrapped in '{' and '}'}) from a path/url.
|
|
3
|
+
* @param path Path/Url
|
|
4
|
+
*
|
|
5
|
+
* @example "foo/{name}/bar" -> ["name"]
|
|
6
|
+
*/
|
|
7
|
+
export function extractParamsFromPath(path) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
return (_b = (_a = path.match(/\{\w+\}/g)) === null || _a === void 0 ? void 0 : _a.map((s) => s.slice(1, -1))) !== null && _b !== void 0 ? _b : [];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;;IAChD,OAAO,MAAA,MAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,0CAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mCAAI,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAM3C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getAllHttpServices } from "./operations.js";
|
|
2
|
+
export function $onValidate(program) {
|
|
3
|
+
// Pass along any diagnostics that might be returned from the HTTP library
|
|
4
|
+
const [, diagnostics] = getAllHttpServices(program);
|
|
5
|
+
if (diagnostics.length > 0) {
|
|
6
|
+
program.reportDiagnostics(diagnostics);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,0EAA0E;IAC1E,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACxC;AACH,CAAC"}
|
package/lib/auth.tsp
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
namespace TypeSpec.Http;
|
|
2
|
+
|
|
3
|
+
@doc("Authentication type")
|
|
4
|
+
enum AuthType {
|
|
5
|
+
@doc("HTTP")
|
|
6
|
+
http,
|
|
7
|
+
|
|
8
|
+
@doc("API key")
|
|
9
|
+
apiKey,
|
|
10
|
+
|
|
11
|
+
@doc("OAuth2")
|
|
12
|
+
oauth2,
|
|
13
|
+
|
|
14
|
+
@doc("OpenID connect")
|
|
15
|
+
openIdConnect,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Basic authentication is a simple authentication scheme built into the HTTP protocol.
|
|
20
|
+
* The client sends HTTP requests with the Authorization header that contains the word Basic word followed by a space and a base64-encoded string username:password.
|
|
21
|
+
* For example, to authorize as demo / `p@55w0rd` the client would send
|
|
22
|
+
* ```
|
|
23
|
+
* Authorization: Basic ZGVtbzpwQDU1dzByZA==
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
model BasicAuth {
|
|
27
|
+
@doc("Http authentication")
|
|
28
|
+
type: AuthType.http;
|
|
29
|
+
|
|
30
|
+
@doc("basic auth scheme")
|
|
31
|
+
scheme: "basic";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens.
|
|
36
|
+
* The name “Bearer authentication” can be understood as “give access to the bearer of this token.” The bearer token is a cryptic string, usually generated by the server in response to a login request.
|
|
37
|
+
* The client must send this token in the Authorization header when making requests to protected resources:
|
|
38
|
+
* ```
|
|
39
|
+
* Authorization: Bearer <token>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
model BearerAuth {
|
|
43
|
+
@doc("Http authentication")
|
|
44
|
+
type: AuthType.http;
|
|
45
|
+
|
|
46
|
+
@doc("bearer auth scheme")
|
|
47
|
+
scheme: "bearer";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@doc("Describes the location of the API key")
|
|
51
|
+
enum ApiKeyLocation {
|
|
52
|
+
@doc("API key is a header value")
|
|
53
|
+
header,
|
|
54
|
+
|
|
55
|
+
@doc("API key is a query parameter")
|
|
56
|
+
query,
|
|
57
|
+
|
|
58
|
+
@doc("API key is found in a cookie")
|
|
59
|
+
cookie,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An API key is a token that a client provides when making API calls. The key can be sent in the query string:
|
|
64
|
+
* ```
|
|
65
|
+
* GET /something?api_key=abcdef12345
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* or as a request header
|
|
69
|
+
*
|
|
70
|
+
* ```
|
|
71
|
+
* GET /something HTTP/1.1
|
|
72
|
+
* X-API-Key: abcdef12345
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* or as a cookie
|
|
76
|
+
*
|
|
77
|
+
* ```
|
|
78
|
+
* GET /something HTTP/1.1
|
|
79
|
+
* Cookie: X-API-KEY=abcdef12345
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
model ApiKeyAuth<TLocation extends ApiKeyLocation, TName extends string> {
|
|
83
|
+
@doc("API key authentication")
|
|
84
|
+
type: AuthType.apiKey;
|
|
85
|
+
|
|
86
|
+
@doc("location of the API key")
|
|
87
|
+
in: TLocation;
|
|
88
|
+
|
|
89
|
+
@doc("name of the API key")
|
|
90
|
+
name: TName;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* OAuth 2.0 is an authorization protocol that gives an API client limited access to user data on a web server.
|
|
95
|
+
* OAuth relies on authentication scenarios called flows, which allow the resource owner (user) to share the protected content from the resource server without sharing their credentials.
|
|
96
|
+
* For that purpose, an OAuth 2.0 server issues access tokens that the client applications can use to access protected resources on behalf of the resource owner.
|
|
97
|
+
* For more information about OAuth 2.0, see oauth.net and RFC 6749.
|
|
98
|
+
*/
|
|
99
|
+
model OAuth2Auth<TFlows extends OAuth2Flow[]> {
|
|
100
|
+
@doc("OAuth2 authentication")
|
|
101
|
+
type: AuthType.oauth2;
|
|
102
|
+
|
|
103
|
+
@doc("Supported OAuth2 flows")
|
|
104
|
+
flows: TFlows;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@doc("Describes the OAuth2 flow type")
|
|
108
|
+
enum OAuth2FlowType {
|
|
109
|
+
@doc("authorization code flow")
|
|
110
|
+
authorizationCode,
|
|
111
|
+
|
|
112
|
+
@doc("implcit flow")
|
|
113
|
+
implicit,
|
|
114
|
+
|
|
115
|
+
@doc("password flow")
|
|
116
|
+
password,
|
|
117
|
+
|
|
118
|
+
@doc("client credential flow")
|
|
119
|
+
clientCredentials,
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
alias OAuth2Flow = AuthorizationCodeFlow | ImplicitFlow | PasswordFlow | ClientCredentialsFlow;
|
|
123
|
+
|
|
124
|
+
@doc("Authorization Code flow")
|
|
125
|
+
model AuthorizationCodeFlow {
|
|
126
|
+
@doc("authorization code flow")
|
|
127
|
+
type: OAuth2FlowType.authorizationCode;
|
|
128
|
+
|
|
129
|
+
@doc("the authorization URL")
|
|
130
|
+
authorizationUrl: string;
|
|
131
|
+
|
|
132
|
+
@doc("the token URL")
|
|
133
|
+
tokenUrl: string;
|
|
134
|
+
|
|
135
|
+
@doc("the refresh URL")
|
|
136
|
+
refreshUrl?: string;
|
|
137
|
+
|
|
138
|
+
@doc("list of scopes for the credential")
|
|
139
|
+
scopes: string[];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@doc("Implicit flow")
|
|
143
|
+
model ImplicitFlow {
|
|
144
|
+
@doc("implicit flow")
|
|
145
|
+
type: OAuth2FlowType.implicit;
|
|
146
|
+
|
|
147
|
+
@doc("the authorization URL")
|
|
148
|
+
authorizationUrl: string;
|
|
149
|
+
|
|
150
|
+
@doc("the refresh URL")
|
|
151
|
+
refreshUrl?: string;
|
|
152
|
+
|
|
153
|
+
@doc("list of scopes for the credential")
|
|
154
|
+
scopes: string[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@doc("Resource Owner Password flow")
|
|
158
|
+
model PasswordFlow {
|
|
159
|
+
@doc("password flow")
|
|
160
|
+
type: OAuth2FlowType.password;
|
|
161
|
+
|
|
162
|
+
@doc("the authorization URL")
|
|
163
|
+
authorizationUrl: string;
|
|
164
|
+
|
|
165
|
+
@doc("the refresh URL")
|
|
166
|
+
refreshUrl?: string;
|
|
167
|
+
|
|
168
|
+
@doc("list of scopes for the credential")
|
|
169
|
+
scopes: string[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@doc("Client credentials flow")
|
|
173
|
+
model ClientCredentialsFlow {
|
|
174
|
+
@doc("client credential flow")
|
|
175
|
+
type: OAuth2FlowType.clientCredentials;
|
|
176
|
+
|
|
177
|
+
@doc("the token URL")
|
|
178
|
+
tokenUrl: string;
|
|
179
|
+
|
|
180
|
+
@doc("the refresh URL")
|
|
181
|
+
refreshUrl?: string;
|
|
182
|
+
|
|
183
|
+
@doc("list of scopes for the credential")
|
|
184
|
+
scopes: string[];
|
|
185
|
+
}
|