mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
add OAuth2 to typescript template (#9466)
* add OAuth to typescript * generate samples
This commit is contained in:
parent
1c733247b1
commit
e1ef7d40b3
@ -75,8 +75,12 @@ export class {{#lambda.pascalcase}}{{name}}{{/lambda.pascalcase}}Authentication
|
||||
public constructor({{#useInversify}}@inject(AbstractTokenProvider) @named("{{name}}") {{/useInversify}}private tokenProvider: TokenProvider) {}
|
||||
{{/isBasicBearer}}
|
||||
{{#isOAuth}}
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
{{/isOAuth}}
|
||||
|
||||
public getName(): string {
|
||||
@ -95,7 +99,7 @@ export class {{#lambda.pascalcase}}{{name}}{{/lambda.pascalcase}}Authentication
|
||||
context.setHeaderParam("Authorization", "Bearer " + await this.tokenProvider.getToken());
|
||||
{{/isBasicBearer}}
|
||||
{{#isOAuth}}
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
{{/isOAuth}}
|
||||
}
|
||||
}
|
||||
@ -119,7 +123,7 @@ export const authMethodServices = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
{{#authMethods}}
|
||||
@ -152,6 +156,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
config["{{name}}"]["tokenProvider"]
|
||||
{{/isBasicBearer}}
|
||||
{{#isOAuth}}
|
||||
config["{{name}}"]["accessToken"]
|
||||
{{/isOAuth}}
|
||||
);
|
||||
}
|
||||
|
@ -48,15 +48,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
||||
* Applies oauth2 authentication to the request context.
|
||||
*/
|
||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
|
||||
public getName(): string {
|
||||
return "petstore_auth";
|
||||
}
|
||||
|
||||
public applySecurityAuthentication(context: RequestContext) {
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +73,7 @@ export type AuthMethods = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
"api_key"?: ApiKeyConfiguration,
|
||||
@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
|
||||
if (config["petstore_auth"]) {
|
||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||
config["petstore_auth"]["accessToken"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -46,15 +46,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
||||
* Applies oauth2 authentication to the request context.
|
||||
*/
|
||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
|
||||
public getName(): string {
|
||||
return "petstore_auth";
|
||||
}
|
||||
|
||||
public applySecurityAuthentication(context: RequestContext) {
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +71,7 @@ export type AuthMethods = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
"api_key"?: ApiKeyConfiguration,
|
||||
@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
|
||||
if (config["petstore_auth"]) {
|
||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||
config["petstore_auth"]["accessToken"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -56,15 +56,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
||||
*/
|
||||
@injectable()
|
||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
|
||||
public getName(): string {
|
||||
return "petstore_auth";
|
||||
}
|
||||
|
||||
public applySecurityAuthentication(context: RequestContext) {
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +86,7 @@ export const authMethodServices = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
"api_key"?: ApiKeyConfiguration,
|
||||
@ -108,6 +112,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
|
||||
if (config["petstore_auth"]) {
|
||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||
config["petstore_auth"]["accessToken"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -46,15 +46,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
||||
* Applies oauth2 authentication to the request context.
|
||||
*/
|
||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
|
||||
public getName(): string {
|
||||
return "petstore_auth";
|
||||
}
|
||||
|
||||
public applySecurityAuthentication(context: RequestContext) {
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +71,7 @@ export type AuthMethods = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
"api_key"?: ApiKeyConfiguration,
|
||||
@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
|
||||
if (config["petstore_auth"]) {
|
||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||
config["petstore_auth"]["accessToken"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,15 +48,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
||||
* Applies oauth2 authentication to the request context.
|
||||
*/
|
||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
||||
// TODO: How to handle oauth2 authentication!
|
||||
public constructor() {}
|
||||
/**
|
||||
* Configures OAuth2 with the necessary properties
|
||||
*
|
||||
* @param accessToken: The access token to be used for every request
|
||||
*/
|
||||
public constructor(private accessToken: string) {}
|
||||
|
||||
public getName(): string {
|
||||
return "petstore_auth";
|
||||
}
|
||||
|
||||
public applySecurityAuthentication(context: RequestContext) {
|
||||
// TODO
|
||||
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +73,7 @@ export type AuthMethods = {
|
||||
export type ApiKeyConfiguration = string;
|
||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||
export type OAuth2Configuration = string;
|
||||
export type OAuth2Configuration = { accessToken: string };
|
||||
|
||||
export type AuthMethodsConfiguration = {
|
||||
"api_key"?: ApiKeyConfiguration,
|
||||
@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
||||
|
||||
if (config["petstore_auth"]) {
|
||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||
config["petstore_auth"]["accessToken"]
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user