forked from loafle/openapi-generator-original
Updated auth
This commit is contained in:
parent
fe2cc24f4d
commit
894bddac1b
@ -33,11 +33,16 @@ export class NoAuthentication extends SecurityAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class APIKeyAuthentication extends SecurityAuthentication {
|
export class APIKeyAuthentication extends SecurityAuthentication {
|
||||||
|
private apiKey: string;
|
||||||
|
|
||||||
public constructor(authName: string, private paramName: string, private apiKey: string, private keyLocation: "query" | "header" | "cookie") {
|
public constructor(authName: string, private paramName: string, private keyLocation: "query" | "header" | "cookie") {
|
||||||
super(authName);
|
super(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setApiKey(apiKey: string) {
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
if (this.keyLocation === "header") {
|
if (this.keyLocation === "header") {
|
||||||
context.setHeaderParam(this.paramName, this.apiKey);
|
context.setHeaderParam(this.paramName, this.apiKey);
|
||||||
@ -50,13 +55,28 @@ export class APIKeyAuthentication extends SecurityAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class HttpBasicAuthentication extends SecurityAuthentication {
|
export class HttpBasicAuthentication extends SecurityAuthentication {
|
||||||
|
private username: string;
|
||||||
public constructor(authName: string, private username: string, private password: string) {
|
private password: string;
|
||||||
|
|
||||||
|
public constructor(authName: string) {
|
||||||
super(authName);
|
super(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setUserNameAndPassword(username: string, password: string) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
let comb = this.username + ":" + this.password;
|
let comb = this.username + ":" + this.password;
|
||||||
context.setHeaderParam("Authentication", "Basic " + btoa(comb));
|
context.setHeaderParam("Authentication", "Basic " + btoa(comb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add oauth2
|
||||||
|
// TODO: check ^last
|
||||||
|
export const authMethods = {
|
||||||
|
{{#authMethods}}
|
||||||
|
"{{name}}": {{#isApiKey}}new APIKeyAuthentication("{{name}}", "{{keyParamName}}", {{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}){{/isApiKey}}{{#isBasic}}new HttpBasicAuthentication("{{keyParamName}}"){{/isBasic}}{{#isOAuth}}null{{/isOAuth}}{{^last}},{{/last}}
|
||||||
|
{{/authMethods}}
|
||||||
|
}
|
||||||
|
@ -33,11 +33,16 @@ export class NoAuthentication extends SecurityAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class APIKeyAuthentication extends SecurityAuthentication {
|
export class APIKeyAuthentication extends SecurityAuthentication {
|
||||||
|
private apiKey: string;
|
||||||
|
|
||||||
public constructor(authName: string, private paramName: string, private apiKey: string, private keyLocation: "query" | "header" | "cookie") {
|
public constructor(authName: string, private paramName: string, private keyLocation: "query" | "header" | "cookie") {
|
||||||
super(authName);
|
super(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setApiKey(apiKey: string) {
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
if (this.keyLocation === "header") {
|
if (this.keyLocation === "header") {
|
||||||
context.setHeaderParam(this.paramName, this.apiKey);
|
context.setHeaderParam(this.paramName, this.apiKey);
|
||||||
@ -50,13 +55,26 @@ export class APIKeyAuthentication extends SecurityAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class HttpBasicAuthentication extends SecurityAuthentication {
|
export class HttpBasicAuthentication extends SecurityAuthentication {
|
||||||
|
private username: string;
|
||||||
public constructor(authName: string, private username: string, private password: string) {
|
private password: string;
|
||||||
|
|
||||||
|
public constructor(authName: string) {
|
||||||
super(authName);
|
super(authName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setUserNameAndPassword(username: string, password: string) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
let comb = this.username + ":" + this.password;
|
let comb = this.username + ":" + this.password;
|
||||||
context.setHeaderParam("Authentication", "Basic " + btoa(comb));
|
context.setHeaderParam("Authentication", "Basic " + btoa(comb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add oauth2
|
||||||
|
export const authMethods = {
|
||||||
|
"api_key": new APIKeyAuthentication("api_key", "api_key", "header"),
|
||||||
|
"petstore_auth": null,
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ export interface ConfigurationParameters {
|
|||||||
baseServer?: ServerConfiguration;
|
baseServer?: ServerConfiguration;
|
||||||
httpApi?: HttpLibrary; // override for fetch implementation
|
httpApi?: HttpLibrary; // override for fetch implementation
|
||||||
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
||||||
|
|
||||||
username?: string; // parameter for basic security
|
username?: string; // parameter for basic security
|
||||||
password?: string; // parameter for basic security
|
password?: string; // parameter for basic security
|
||||||
apiKey?: string | ((name: string) => string); // parameter for apiKey security
|
apiKey?: string | ((name: string) => string); // parameter for apiKey security
|
||||||
|
@ -11,5 +11,5 @@ export class ServerConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const servers = [
|
export const servers = [
|
||||||
new ServerConfiguration("http://petstore.swagger.io/v2"),
|
new ServerConfiguration("/"),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user