use keyParamName (#17328)

This commit is contained in:
devhl-labs 2023-12-06 01:49:55 -05:00 committed by GitHub
parent 39d5b4ebf9
commit 0ab9f74cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 152 deletions

View File

@ -31,7 +31,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#apiKeyMethods}} {{#apiKeyMethods}}
string apiKeyTokenValue{{-index}} = context.Configuration["<token>"] ?? throw new Exception("Token not found."); string apiKeyTokenValue{{-index}} = context.Configuration["<token>"] ?? throw new Exception("Token not found.");
ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}(apiKeyTokenValue{{-index}}, ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1)); ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}(apiKeyTokenValue{{-index}}, ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{keyParamName}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1));
options.AddTokens(apiKeyToken{{-index}}); options.AddTokens(apiKeyToken{{-index}});
{{/apiKeyMethods}} {{/apiKeyMethods}}

View File

@ -21,7 +21,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{ {
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#apiKeyMethods}} {{#apiKeyMethods}}
ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1)); ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{keyParamName}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1));
options.AddTokens(apiKeyToken{{-index}}); options.AddTokens(apiKeyToken{{-index}});
{{/apiKeyMethods}} {{/apiKeyMethods}}
@ -55,7 +55,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{ {
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#apiKeyMethods}} {{#apiKeyMethods}}
ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1)); ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{keyParamName}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1));
options.AddTokens(apiKeyToken{{-index}}); options.AddTokens(apiKeyToken{{-index}});
{{/apiKeyMethods}} {{/apiKeyMethods}}
@ -92,7 +92,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{ {
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#apiKeyMethods}} {{#apiKeyMethods}}
ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1)); ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{keyParamName}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1));
options.AddTokens(apiKeyToken{{-index}}); options.AddTokens(apiKeyToken{{-index}});
{{/apiKeyMethods}} {{/apiKeyMethods}}
@ -129,7 +129,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{ {
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#apiKeyMethods}} {{#apiKeyMethods}}
ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1)); ApiKeyToken apiKeyToken{{-index}} = new{{^net70OrLater}} ApiKeyToken{{/net70OrLater}}("<token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{keyParamName}}{{/lambda.titlecase}}, timeout: TimeSpan.FromSeconds(1));
options.AddTokens(apiKeyToken{{-index}}); options.AddTokens(apiKeyToken{{-index}});
{{/apiKeyMethods}} {{/apiKeyMethods}}

View File

@ -80,14 +80,18 @@ namespace YourProject
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.Configure{{apiName}}((context, options) => .Configure{{apiName}}((context, options) =>
{ {
{{#authMethods}}// the type of token here depends on the api security specifications {{#authMethods}}
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}); {{#-first}}
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
options.AddTokens(token); options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider // optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>(); options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
{{/authMethods}}options.ConfigureJsonOptions((jsonOptions) => {{/-first}}
{{/authMethods}}
options.ConfigureJsonOptions((jsonOptions) =>
{ {
// your custom converters if any // your custom converters if any
}); });

View File

@ -69,42 +69,7 @@ namespace YourProject
.ConfigureApi((context, options) => .ConfigureApi((context, options) =>
{ {
// the type of token here depends on the api security specifications // the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Petstore_auth); ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key_query);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_basic_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Bearer_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_signature_test);
options.AddTokens(token); options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider // optionally choose the method the tokens will be provided with, default is RateLimitProvider

View File

@ -69,42 +69,7 @@ namespace YourProject
.ConfigureApi((context, options) => .ConfigureApi((context, options) =>
{ {
// the type of token here depends on the api security specifications // the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Petstore_auth); ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key_query);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_basic_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Bearer_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_signature_test);
options.AddTokens(token); options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider // optionally choose the method the tokens will be provided with, default is RateLimitProvider

View File

@ -69,42 +69,7 @@ namespace YourProject
.ConfigureApi((context, options) => .ConfigureApi((context, options) =>
{ {
// the type of token here depends on the api security specifications // the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Petstore_auth); ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key_query);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_basic_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Bearer_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_signature_test);
options.AddTokens(token); options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider // optionally choose the method the tokens will be provided with, default is RateLimitProvider

View File

@ -69,42 +69,7 @@ namespace YourProject
.ConfigureApi((context, options) => .ConfigureApi((context, options) =>
{ {
// the type of token here depends on the api security specifications // the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Petstore_auth); ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Api_key_query);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_basic_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Bearer_test);
options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
// the type of token here depends on the api security specifications
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Http_signature_test);
options.AddTokens(token); options.AddTokens(token);
// optionally choose the method the tokens will be provided with, default is RateLimitProvider // optionally choose the method the tokens will be provided with, default is RateLimitProvider