diff --git a/modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache b/modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache index 332760455bf..bfb303e741e 100644 --- a/modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache @@ -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}} ); } diff --git a/samples/openapi3/client/petstore/typescript/builds/default/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/default/auth/auth.ts index 9d59a0a2558..1f1d1ecac67 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/auth/auth.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/auth/auth.ts @@ -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"] ); } diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/deno/auth/auth.ts index 0a02d2e58d2..e7609dabbec 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/auth/auth.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/auth/auth.ts @@ -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"] ); } diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/auth/auth.ts index 13e3b17fa82..f6ffebc4d7e 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/auth/auth.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/auth/auth.ts @@ -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"] ); } diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/auth/auth.ts index 2cdf0800f32..d8924a4216c 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/auth/auth.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/auth/auth.ts @@ -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"] ); } diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/auth/auth.ts index 9d59a0a2558..1f1d1ecac67 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/auth/auth.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/auth/auth.ts @@ -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"] ); }