mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
feat: support bearer authentication (#21110)
This commit is contained in:
parent
3fa806006b
commit
be77442bff
@ -188,7 +188,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|BasicAuth|✓|OAS2,OAS3
|
||||
|ApiKey|✗|OAS2,OAS3
|
||||
|OpenIDConnect|✗|OAS3
|
||||
|BearerToken|✗|OAS3
|
||||
|BearerToken|✓|OAS3
|
||||
|OAuth2_Implicit|✓|OAS2,OAS3
|
||||
|OAuth2_Password|✗|OAS2,OAS3
|
||||
|OAuth2_ClientCredentials|✗|OAS2,OAS3
|
||||
|
@ -71,7 +71,8 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||
.securityFeatures(EnumSet.of(
|
||||
SecurityFeature.OAuth2_Implicit,
|
||||
SecurityFeature.BasicAuth))
|
||||
SecurityFeature.BasicAuth,
|
||||
SecurityFeature.BearerToken))
|
||||
.excludeGlobalFeatures(
|
||||
GlobalFeature.XMLStructureDefinitions,
|
||||
GlobalFeature.Callbacks,
|
||||
|
@ -52,6 +52,9 @@ defmodule {{moduleName}}.Connection do
|
||||
- `username`: A username for basic authentication.
|
||||
- `password`: A password for basic authentication.
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasHttpBearerMethods}}
|
||||
- `bearer_token`: A bearer token for bearer authentication.
|
||||
{{/hasHttpBearerMethods}}
|
||||
"""
|
||||
@type options :: [
|
||||
{:base_url, String.t()},
|
||||
@ -64,6 +67,9 @@ defmodule {{moduleName}}.Connection do
|
||||
{:username, String.t() | nil},
|
||||
{:password, String.t() | nil},
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasHttpBearerMethods}}
|
||||
{:bearer_token, String.t() | nil},
|
||||
{{/hasHttpBearerMethods}}
|
||||
]
|
||||
|
||||
@doc "Forward requests to Tesla."
|
||||
@ -240,6 +246,11 @@ defmodule {{moduleName}}.Connection do
|
||||
end
|
||||
{{/hasHttpBasicMethods}}
|
||||
|
||||
{{#hasHttpBearerMethods}}
|
||||
bearer_token = Keyword.get(options, :bearer_token)
|
||||
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
|
||||
{{/hasHttpBearerMethods}}
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
middleware =
|
||||
if token = Keyword.get(options, :token) do
|
||||
|
@ -46,6 +46,7 @@ defmodule OpenapiPetstore.Connection do
|
||||
fetcher function.
|
||||
- `username`: A username for basic authentication.
|
||||
- `password`: A password for basic authentication.
|
||||
- `bearer_token`: A bearer token for bearer authentication.
|
||||
"""
|
||||
@type options :: [
|
||||
{:base_url, String.t()},
|
||||
@ -54,6 +55,7 @@ defmodule OpenapiPetstore.Connection do
|
||||
{:token_scopes, list(String.t())},
|
||||
{:username, String.t() | nil},
|
||||
{:password, String.t() | nil},
|
||||
{:bearer_token, String.t() | nil},
|
||||
]
|
||||
|
||||
@doc "Forward requests to Tesla."
|
||||
@ -175,6 +177,9 @@ defmodule OpenapiPetstore.Connection do
|
||||
middleware
|
||||
end
|
||||
|
||||
bearer_token = Keyword.get(options, :bearer_token)
|
||||
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
|
||||
|
||||
middleware =
|
||||
if token = Keyword.get(options, :token) do
|
||||
scopes = Keyword.get(options, :token_scopes, @default_scopes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user