forked from loafle/openapi-generator-original
		
	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
 | 
					|BasicAuth|✓|OAS2,OAS3
 | 
				
			||||||
|ApiKey|✗|OAS2,OAS3
 | 
					|ApiKey|✗|OAS2,OAS3
 | 
				
			||||||
|OpenIDConnect|✗|OAS3
 | 
					|OpenIDConnect|✗|OAS3
 | 
				
			||||||
|BearerToken|✗|OAS3
 | 
					|BearerToken|✓|OAS3
 | 
				
			||||||
|OAuth2_Implicit|✓|OAS2,OAS3
 | 
					|OAuth2_Implicit|✓|OAS2,OAS3
 | 
				
			||||||
|OAuth2_Password|✗|OAS2,OAS3
 | 
					|OAuth2_Password|✗|OAS2,OAS3
 | 
				
			||||||
|OAuth2_ClientCredentials|✗|OAS2,OAS3
 | 
					|OAuth2_ClientCredentials|✗|OAS2,OAS3
 | 
				
			||||||
 | 
				
			|||||||
@ -71,7 +71,8 @@ public class ElixirClientCodegen extends DefaultCodegen {
 | 
				
			|||||||
                .includeDocumentationFeatures(DocumentationFeature.Readme)
 | 
					                .includeDocumentationFeatures(DocumentationFeature.Readme)
 | 
				
			||||||
                .securityFeatures(EnumSet.of(
 | 
					                .securityFeatures(EnumSet.of(
 | 
				
			||||||
                        SecurityFeature.OAuth2_Implicit,
 | 
					                        SecurityFeature.OAuth2_Implicit,
 | 
				
			||||||
                        SecurityFeature.BasicAuth))
 | 
					                        SecurityFeature.BasicAuth,
 | 
				
			||||||
 | 
					                        SecurityFeature.BearerToken))
 | 
				
			||||||
                .excludeGlobalFeatures(
 | 
					                .excludeGlobalFeatures(
 | 
				
			||||||
                        GlobalFeature.XMLStructureDefinitions,
 | 
					                        GlobalFeature.XMLStructureDefinitions,
 | 
				
			||||||
                        GlobalFeature.Callbacks,
 | 
					                        GlobalFeature.Callbacks,
 | 
				
			||||||
 | 
				
			|||||||
@ -52,6 +52,9 @@ defmodule {{moduleName}}.Connection do
 | 
				
			|||||||
  - `username`: A username for basic authentication.
 | 
					  - `username`: A username for basic authentication.
 | 
				
			||||||
  - `password`: A password for basic authentication.
 | 
					  - `password`: A password for basic authentication.
 | 
				
			||||||
  {{/hasHttpBasicMethods}}
 | 
					  {{/hasHttpBasicMethods}}
 | 
				
			||||||
 | 
					  {{#hasHttpBearerMethods}}
 | 
				
			||||||
 | 
					  - `bearer_token`: A bearer token for bearer authentication.
 | 
				
			||||||
 | 
					  {{/hasHttpBearerMethods}}
 | 
				
			||||||
  """
 | 
					  """
 | 
				
			||||||
  @type options :: [
 | 
					  @type options :: [
 | 
				
			||||||
          {:base_url, String.t()},
 | 
					          {:base_url, String.t()},
 | 
				
			||||||
@ -64,6 +67,9 @@ defmodule {{moduleName}}.Connection do
 | 
				
			|||||||
          {:username, String.t() | nil},
 | 
					          {:username, String.t() | nil},
 | 
				
			||||||
          {:password, String.t() | nil},
 | 
					          {:password, String.t() | nil},
 | 
				
			||||||
  {{/hasHttpBasicMethods}}
 | 
					  {{/hasHttpBasicMethods}}
 | 
				
			||||||
 | 
					  {{#hasHttpBearerMethods}}
 | 
				
			||||||
 | 
					          {:bearer_token, String.t() | nil},
 | 
				
			||||||
 | 
					  {{/hasHttpBearerMethods}}
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @doc "Forward requests to Tesla."
 | 
					  @doc "Forward requests to Tesla."
 | 
				
			||||||
@ -240,6 +246,11 @@ defmodule {{moduleName}}.Connection do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
    {{/hasHttpBasicMethods}}
 | 
					    {{/hasHttpBasicMethods}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {{#hasHttpBearerMethods}}
 | 
				
			||||||
 | 
					    bearer_token = Keyword.get(options, :bearer_token)
 | 
				
			||||||
 | 
					    middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
 | 
				
			||||||
 | 
					    {{/hasHttpBearerMethods}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{#hasOAuthMethods}}
 | 
					    {{#hasOAuthMethods}}
 | 
				
			||||||
    middleware =
 | 
					    middleware =
 | 
				
			||||||
      if token = Keyword.get(options, :token) do
 | 
					      if token = Keyword.get(options, :token) do
 | 
				
			||||||
 | 
				
			|||||||
@ -46,6 +46,7 @@ defmodule OpenapiPetstore.Connection do
 | 
				
			|||||||
    fetcher function.
 | 
					    fetcher function.
 | 
				
			||||||
  - `username`: A username for basic authentication.
 | 
					  - `username`: A username for basic authentication.
 | 
				
			||||||
  - `password`: A password for basic authentication.
 | 
					  - `password`: A password for basic authentication.
 | 
				
			||||||
 | 
					  - `bearer_token`: A bearer token for bearer authentication.
 | 
				
			||||||
  """
 | 
					  """
 | 
				
			||||||
  @type options :: [
 | 
					  @type options :: [
 | 
				
			||||||
          {:base_url, String.t()},
 | 
					          {:base_url, String.t()},
 | 
				
			||||||
@ -54,6 +55,7 @@ defmodule OpenapiPetstore.Connection do
 | 
				
			|||||||
          {:token_scopes, list(String.t())},
 | 
					          {:token_scopes, list(String.t())},
 | 
				
			||||||
          {:username, String.t() | nil},
 | 
					          {:username, String.t() | nil},
 | 
				
			||||||
          {:password, String.t() | nil},
 | 
					          {:password, String.t() | nil},
 | 
				
			||||||
 | 
					          {:bearer_token, String.t() | nil},
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @doc "Forward requests to Tesla."
 | 
					  @doc "Forward requests to Tesla."
 | 
				
			||||||
@ -175,6 +177,9 @@ defmodule OpenapiPetstore.Connection do
 | 
				
			|||||||
        middleware
 | 
					        middleware
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bearer_token = Keyword.get(options, :bearer_token)
 | 
				
			||||||
 | 
					    middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    middleware =
 | 
					    middleware =
 | 
				
			||||||
      if token = Keyword.get(options, :token) do
 | 
					      if token = Keyword.get(options, :token) do
 | 
				
			||||||
        scopes = Keyword.get(options, :token_scopes, @default_scopes)
 | 
					        scopes = Keyword.get(options, :token_scopes, @default_scopes)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user