Skip to content

Commit be77442

Browse files
authored
feat: support bearer authentication (#21110)
1 parent 3fa8060 commit be77442

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

docs/generators/elixir.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
188188
|BasicAuth|✓|OAS2,OAS3
189189
|ApiKey|✗|OAS2,OAS3
190190
|OpenIDConnect|✗|OAS3
191-
|BearerToken||OAS3
191+
|BearerToken||OAS3
192192
|OAuth2_Implicit|✓|OAS2,OAS3
193193
|OAuth2_Password|✗|OAS2,OAS3
194194
|OAuth2_ClientCredentials|✗|OAS2,OAS3

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public ElixirClientCodegen() {
7171
.includeDocumentationFeatures(DocumentationFeature.Readme)
7272
.securityFeatures(EnumSet.of(
7373
SecurityFeature.OAuth2_Implicit,
74-
SecurityFeature.BasicAuth))
74+
SecurityFeature.BasicAuth,
75+
SecurityFeature.BearerToken))
7576
.excludeGlobalFeatures(
7677
GlobalFeature.XMLStructureDefinitions,
7778
GlobalFeature.Callbacks,

modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ defmodule {{moduleName}}.Connection do
5252
- `username`: A username for basic authentication.
5353
- `password`: A password for basic authentication.
5454
{{/hasHttpBasicMethods}}
55+
{{#hasHttpBearerMethods}}
56+
- `bearer_token`: A bearer token for bearer authentication.
57+
{{/hasHttpBearerMethods}}
5558
"""
5659
@type options :: [
5760
{:base_url, String.t()},
@@ -64,6 +67,9 @@ defmodule {{moduleName}}.Connection do
6467
{:username, String.t() | nil},
6568
{:password, String.t() | nil},
6669
{{/hasHttpBasicMethods}}
70+
{{#hasHttpBearerMethods}}
71+
{:bearer_token, String.t() | nil},
72+
{{/hasHttpBearerMethods}}
6773
]
6874

6975
@doc "Forward requests to Tesla."
@@ -240,6 +246,11 @@ defmodule {{moduleName}}.Connection do
240246
end
241247
{{/hasHttpBasicMethods}}
242248

249+
{{#hasHttpBearerMethods}}
250+
bearer_token = Keyword.get(options, :bearer_token)
251+
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
252+
{{/hasHttpBearerMethods}}
253+
243254
{{#hasOAuthMethods}}
244255
middleware =
245256
if token = Keyword.get(options, :token) do

samples/client/petstore/elixir/lib/openapi_petstore/connection.ex

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ defmodule OpenapiPetstore.Connection do
4646
fetcher function.
4747
- `username`: A username for basic authentication.
4848
- `password`: A password for basic authentication.
49+
- `bearer_token`: A bearer token for bearer authentication.
4950
"""
5051
@type options :: [
5152
{:base_url, String.t()},
@@ -54,6 +55,7 @@ defmodule OpenapiPetstore.Connection do
5455
{:token_scopes, list(String.t())},
5556
{:username, String.t() | nil},
5657
{:password, String.t() | nil},
58+
{:bearer_token, String.t() | nil},
5759
]
5860

5961
@doc "Forward requests to Tesla."
@@ -175,6 +177,9 @@ defmodule OpenapiPetstore.Connection do
175177
middleware
176178
end
177179

180+
bearer_token = Keyword.get(options, :bearer_token)
181+
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
182+
178183
middleware =
179184
if token = Keyword.get(options, :token) do
180185
scopes = Keyword.get(options, :token_scopes, @default_scopes)

0 commit comments

Comments
 (0)