forked from loafle/openapi-generator-original
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) {}
|
public constructor({{#useInversify}}@inject(AbstractTokenProvider) @named("{{name}}") {{/useInversify}}private tokenProvider: TokenProvider) {}
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{#isOAuth}}
|
{{#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}}
|
{{/isOAuth}}
|
||||||
|
|
||||||
public getName(): string {
|
public getName(): string {
|
||||||
@ -95,7 +99,7 @@ export class {{#lambda.pascalcase}}{{name}}{{/lambda.pascalcase}}Authentication
|
|||||||
context.setHeaderParam("Authorization", "Bearer " + await this.tokenProvider.getToken());
|
context.setHeaderParam("Authorization", "Bearer " + await this.tokenProvider.getToken());
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +123,7 @@ export const authMethodServices = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
@ -152,6 +156,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
config["{{name}}"]["tokenProvider"]
|
config["{{name}}"]["tokenProvider"]
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
|
config["{{name}}"]["accessToken"]
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -48,15 +48,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
|||||||
* Applies oauth2 authentication to the request context.
|
* Applies oauth2 authentication to the request context.
|
||||||
*/
|
*/
|
||||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
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 {
|
public getName(): string {
|
||||||
return "petstore_auth";
|
return "petstore_auth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +73,7 @@ export type AuthMethods = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
"api_key"?: ApiKeyConfiguration,
|
"api_key"?: ApiKeyConfiguration,
|
||||||
@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
|
|
||||||
if (config["petstore_auth"]) {
|
if (config["petstore_auth"]) {
|
||||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
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.
|
* Applies oauth2 authentication to the request context.
|
||||||
*/
|
*/
|
||||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
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 {
|
public getName(): string {
|
||||||
return "petstore_auth";
|
return "petstore_auth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +71,7 @@ export type AuthMethods = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
"api_key"?: ApiKeyConfiguration,
|
"api_key"?: ApiKeyConfiguration,
|
||||||
@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
|
|
||||||
if (config["petstore_auth"]) {
|
if (config["petstore_auth"]) {
|
||||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||||
|
config["petstore_auth"]["accessToken"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,15 +56,19 @@ export class ApiKeyAuthentication implements SecurityAuthentication {
|
|||||||
*/
|
*/
|
||||||
@injectable()
|
@injectable()
|
||||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
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 {
|
public getName(): string {
|
||||||
return "petstore_auth";
|
return "petstore_auth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ export const authMethodServices = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
"api_key"?: ApiKeyConfiguration,
|
"api_key"?: ApiKeyConfiguration,
|
||||||
@ -108,6 +112,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
|
|
||||||
if (config["petstore_auth"]) {
|
if (config["petstore_auth"]) {
|
||||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
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.
|
* Applies oauth2 authentication to the request context.
|
||||||
*/
|
*/
|
||||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
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 {
|
public getName(): string {
|
||||||
return "petstore_auth";
|
return "petstore_auth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +71,7 @@ export type AuthMethods = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
"api_key"?: ApiKeyConfiguration,
|
"api_key"?: ApiKeyConfiguration,
|
||||||
@ -93,6 +97,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
|
|
||||||
if (config["petstore_auth"]) {
|
if (config["petstore_auth"]) {
|
||||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
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.
|
* Applies oauth2 authentication to the request context.
|
||||||
*/
|
*/
|
||||||
export class PetstoreAuthAuthentication implements SecurityAuthentication {
|
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 {
|
public getName(): string {
|
||||||
return "petstore_auth";
|
return "petstore_auth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public applySecurityAuthentication(context: RequestContext) {
|
public applySecurityAuthentication(context: RequestContext) {
|
||||||
// TODO
|
context.setHeaderParam("Authorization", "Bearer " + this.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +73,7 @@ export type AuthMethods = {
|
|||||||
export type ApiKeyConfiguration = string;
|
export type ApiKeyConfiguration = string;
|
||||||
export type HttpBasicConfiguration = { "username": string, "password": string };
|
export type HttpBasicConfiguration = { "username": string, "password": string };
|
||||||
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
|
||||||
export type OAuth2Configuration = string;
|
export type OAuth2Configuration = { accessToken: string };
|
||||||
|
|
||||||
export type AuthMethodsConfiguration = {
|
export type AuthMethodsConfiguration = {
|
||||||
"api_key"?: ApiKeyConfiguration,
|
"api_key"?: ApiKeyConfiguration,
|
||||||
@ -95,6 +99,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
|
|||||||
|
|
||||||
if (config["petstore_auth"]) {
|
if (config["petstore_auth"]) {
|
||||||
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
authMethods["petstore_auth"] = new PetstoreAuthAuthentication(
|
||||||
|
config["petstore_auth"]["accessToken"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user