Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OAuth2 to typescript template #9466

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}}
}
}
Expand All @@ -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}}
Expand Down Expand Up @@ -152,6 +156,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
config["{{name}}"]["tokenProvider"]
{{/isBasicBearer}}
{{#isOAuth}}
config["{{name}}"]["accessToken"]
{{/isOAuth}}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand All @@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine

if (config["petstore_auth"]) {
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
config["petstore_auth"]["accessToken"]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand All @@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine

if (config["petstore_auth"]) {
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
config["petstore_auth"]["accessToken"]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand All @@ -108,6 +112,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine

if (config["petstore_auth"]) {
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
config["petstore_auth"]["accessToken"]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand All @@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine

if (config["petstore_auth"]) {
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
config["petstore_auth"]["accessToken"]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand All @@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine

if (config["petstore_auth"]) {
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
config["petstore_auth"]["accessToken"]
);
}

Expand Down