forked from loafle/openapi-generator-original
Enable access token refresh (#14251)
* Enable the ruby client to support refreshing access tokens - The client can now be configured with an access token getter proc - The proc overrides the the static access token if it is set * Run generators
This commit is contained in:
parent
851ddecda3
commit
02d4852f26
@ -70,13 +70,17 @@ require '{{{gemName}}}'
|
|||||||
config.username = 'YOUR_USERNAME'
|
config.username = 'YOUR_USERNAME'
|
||||||
config.password = 'YOUR_PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}}
|
config.password = 'YOUR_PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}}
|
||||||
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
|
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
|
||||||
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
|
config.access_token = 'YOUR_BEARER_TOKEN'
|
||||||
|
# Configure a proc to get access tokens in lieu of the static access_token configuration
|
||||||
|
config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' } {{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
|
||||||
# Configure API key authorization: {{{name}}}
|
# Configure API key authorization: {{{name}}}
|
||||||
config.api_key['{{{name}}}'] = 'YOUR API KEY'
|
config.api_key['{{{name}}}'] = 'YOUR API KEY'
|
||||||
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
|
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
|
||||||
# config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
|
# config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
|
||||||
# Configure OAuth2 access token for authorization: {{{name}}}
|
# Configure OAuth2 access token for authorization: {{{name}}}
|
||||||
config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
|
config.access_token = 'YOUR ACCESS TOKEN'
|
||||||
|
# Configure a proc to get access tokens in lieu of the static access_token configuration
|
||||||
|
config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' } {{/isOAuth}}
|
||||||
{{/authMethods}}end
|
{{/authMethods}}end
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
|
|
||||||
|
@ -54,6 +54,11 @@ module {{moduleName}}
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -178,6 +183,12 @@ module {{moduleName}}
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
@ -215,7 +226,7 @@ module {{moduleName}}
|
|||||||
format: '{{{.}}}',
|
format: '{{{.}}}',
|
||||||
{{/bearerFormat}}
|
{{/bearerFormat}}
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
@ -225,7 +236,7 @@ module {{moduleName}}
|
|||||||
type: 'oauth2',
|
type: 'oauth2',
|
||||||
in: 'header',
|
in: 'header',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
|
@ -62,6 +62,11 @@ module Petstore
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -208,6 +213,12 @@ module Petstore
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
@ -236,7 +247,7 @@ module Petstore
|
|||||||
in: 'header',
|
in: 'header',
|
||||||
format: 'JWT',
|
format: 'JWT',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
'http_basic_test' =>
|
'http_basic_test' =>
|
||||||
{
|
{
|
||||||
@ -250,7 +261,7 @@ module Petstore
|
|||||||
type: 'oauth2',
|
type: 'oauth2',
|
||||||
in: 'header',
|
in: 'header',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,11 @@ module Petstore
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -211,6 +216,12 @@ module Petstore
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
@ -239,7 +250,7 @@ module Petstore
|
|||||||
in: 'header',
|
in: 'header',
|
||||||
format: 'JWT',
|
format: 'JWT',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
'http_basic_test' =>
|
'http_basic_test' =>
|
||||||
{
|
{
|
||||||
@ -253,7 +264,7 @@ module Petstore
|
|||||||
type: 'oauth2',
|
type: 'oauth2',
|
||||||
in: 'header',
|
in: 'header',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,11 @@ module Petstore
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -208,6 +213,12 @@ module Petstore
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
@ -236,7 +247,7 @@ module Petstore
|
|||||||
in: 'header',
|
in: 'header',
|
||||||
format: 'JWT',
|
format: 'JWT',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
'http_basic_test' =>
|
'http_basic_test' =>
|
||||||
{
|
{
|
||||||
@ -250,7 +261,7 @@ module Petstore
|
|||||||
type: 'oauth2',
|
type: 'oauth2',
|
||||||
in: 'header',
|
in: 'header',
|
||||||
key: 'Authorization',
|
key: 'Authorization',
|
||||||
value: "Bearer #{access_token}"
|
value: "Bearer #{access_token_with_refresh}"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,11 @@ module XAuthIDAlias
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -208,6 +213,12 @@ module XAuthIDAlias
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
|
@ -62,6 +62,11 @@ module DynamicServers
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -208,6 +213,12 @@ module DynamicServers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
|
@ -62,6 +62,11 @@ module Petstore
|
|||||||
# Defines the access token (Bearer) used with OAuth2.
|
# Defines the access token (Bearer) used with OAuth2.
|
||||||
attr_accessor :access_token
|
attr_accessor :access_token
|
||||||
|
|
||||||
|
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
||||||
|
# Overrides the access_token if set
|
||||||
|
# @return [Proc]
|
||||||
|
attr_accessor :access_token_getter
|
||||||
|
|
||||||
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
||||||
# details will be logged with `logger.debug` (see the `logger` attribute).
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
||||||
# Default to false.
|
# Default to false.
|
||||||
@ -208,6 +213,12 @@ module Petstore
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets access_token using access_token_getter or uses the static access_token
|
||||||
|
def access_token_with_refresh
|
||||||
|
return access_token if access_token_getter.nil?
|
||||||
|
access_token_getter.call
|
||||||
|
end
|
||||||
|
|
||||||
# Gets Basic Auth token string
|
# Gets Basic Auth token string
|
||||||
def basic_auth_token
|
def basic_auth_token
|
||||||
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user