forked from loafle/openapi-generator-original
add refresh token setting, use oauth_client_secret instead
This commit is contained in:
parent
c4dd42e7a0
commit
19eeebf083
@ -24,7 +24,7 @@
|
|||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
#' @field access_token Access token
|
#' @field access_token Access token
|
||||||
#' @field oauth_client_id OAuth client ID
|
#' @field oauth_client_id OAuth client ID
|
||||||
#' @field oauth_secret OAuth secret
|
#' @field oauth_client_secret OAuth secret
|
||||||
#' @field oauth_refresh_token OAuth refresh token
|
#' @field oauth_refresh_token OAuth refresh token
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
@ -65,7 +65,7 @@ ApiClient <- R6::R6Class(
|
|||||||
# OAuth2 client ID
|
# OAuth2 client ID
|
||||||
oauth_client_id = NULL,
|
oauth_client_id = NULL,
|
||||||
# OAuth2 secret
|
# OAuth2 secret
|
||||||
oauth_secret = NULL,
|
oauth_client_secret = NULL,
|
||||||
# OAuth2 refresh token
|
# OAuth2 refresh token
|
||||||
oauth_refresh_token = NULL,
|
oauth_refresh_token = NULL,
|
||||||
# OAuth2
|
# OAuth2
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
#' @field access_token Access token
|
#' @field access_token Access token
|
||||||
#' @field oauth_client_id OAuth client ID
|
#' @field oauth_client_id OAuth client ID
|
||||||
#' @field oauth_secret OAuth secret
|
#' @field oauth_client_secret OAuth secret
|
||||||
#' @field oauth_refresh_token OAuth refresh token
|
#' @field oauth_refresh_token OAuth refresh token
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
@ -33,6 +33,7 @@
|
|||||||
#' @field oauth_token_url Token URL
|
#' @field oauth_token_url Token URL
|
||||||
#' @field oauth_pkce Boolean flag to enable PKCE
|
#' @field oauth_pkce Boolean flag to enable PKCE
|
||||||
#' @field oauth_scopes OAuth scopes
|
#' @field oauth_scopes OAuth scopes
|
||||||
|
#' @field oauth_scopes OAuth scopes
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
{{/hasOAuthMethods}}
|
{{/hasOAuthMethods}}
|
||||||
@ -65,9 +66,11 @@ ApiClient <- R6::R6Class(
|
|||||||
# OAuth2 client ID
|
# OAuth2 client ID
|
||||||
oauth_client_id = NULL,
|
oauth_client_id = NULL,
|
||||||
# OAuth2 secret
|
# OAuth2 secret
|
||||||
oauth_secret = NULL,
|
oauth_client_secret = NULL,
|
||||||
# OAuth2 refresh token
|
# OAuth2 refresh token
|
||||||
oauth_refresh_token = NULL,
|
oauth_refresh_token = NULL,
|
||||||
|
# OAuth2 auto refresh token
|
||||||
|
oauth_auto_refresh_token = FALSE,
|
||||||
# OAuth2
|
# OAuth2
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
@ -187,6 +190,7 @@ ApiClient <- R6::R6Class(
|
|||||||
# set the URL
|
# set the URL
|
||||||
req <- request(url)
|
req <- request(url)
|
||||||
|
|
||||||
|
# make the call via httr, which comes with retry logic
|
||||||
resp <- self$Execute(req, method, query_params, header_params, form_params,
|
resp <- self$Execute(req, method, query_params, header_params, form_params,
|
||||||
file_params, accepts, content_types, body, is_oauth = is_oauth,
|
file_params, accepts, content_types, body, is_oauth = is_oauth,
|
||||||
oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...)
|
oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...)
|
||||||
@ -278,10 +282,10 @@ ApiClient <- R6::R6Class(
|
|||||||
|
|
||||||
{{#hasOAuthMethods}}
|
{{#hasOAuthMethods}}
|
||||||
# use oauth authentication if the endpoint requires it
|
# use oauth authentication if the endpoint requires it
|
||||||
if (is_oauth && !is.null(self$oauth_client_id) && !is.null(self$oauth_secret)) {
|
if (is_oauth && !is.null(self$oauth_client_id) && !is.null(self$oauth_client_secret)) {
|
||||||
client <- oauth_client(
|
client <- oauth_client(
|
||||||
id = self$oauth_client_id,
|
id = self$oauth_client_id,
|
||||||
secret = obfuscated(self$oauth_secret),
|
secret = obfuscated(self$oauth_client_secret),
|
||||||
token_url = self$oauth_token_url,
|
token_url = self$oauth_token_url,
|
||||||
name = "{{packageName}}-oauth"
|
name = "{{packageName}}-oauth"
|
||||||
)
|
)
|
||||||
|
@ -30,13 +30,14 @@
|
|||||||
#' @field api_keys API keys
|
#' @field api_keys API keys
|
||||||
#' @field access_token Access token
|
#' @field access_token Access token
|
||||||
#' @field oauth_client_id OAuth client ID
|
#' @field oauth_client_id OAuth client ID
|
||||||
#' @field oauth_secret OAuth secret
|
#' @field oauth_client_secret OAuth secret
|
||||||
#' @field oauth_refresh_token OAuth refresh token
|
#' @field oauth_refresh_token OAuth refresh token
|
||||||
#' @field oauth_flow_type OAuth flow type
|
#' @field oauth_flow_type OAuth flow type
|
||||||
#' @field oauth_authorization_url Authoriziation URL
|
#' @field oauth_authorization_url Authoriziation URL
|
||||||
#' @field oauth_token_url Token URL
|
#' @field oauth_token_url Token URL
|
||||||
#' @field oauth_pkce Boolean flag to enable PKCE
|
#' @field oauth_pkce Boolean flag to enable PKCE
|
||||||
#' @field oauth_scopes OAuth scopes
|
#' @field oauth_scopes OAuth scopes
|
||||||
|
#' @field oauth_scopes OAuth scopes
|
||||||
#' @field bearer_token Bearer token
|
#' @field bearer_token Bearer token
|
||||||
#' @field timeout Default timeout in seconds
|
#' @field timeout Default timeout in seconds
|
||||||
#' @field retry_status_codes vector of status codes to retry
|
#' @field retry_status_codes vector of status codes to retry
|
||||||
@ -63,9 +64,11 @@ ApiClient <- R6::R6Class(
|
|||||||
# OAuth2 client ID
|
# OAuth2 client ID
|
||||||
oauth_client_id = NULL,
|
oauth_client_id = NULL,
|
||||||
# OAuth2 secret
|
# OAuth2 secret
|
||||||
oauth_secret = NULL,
|
oauth_client_secret = NULL,
|
||||||
# OAuth2 refresh token
|
# OAuth2 refresh token
|
||||||
oauth_refresh_token = NULL,
|
oauth_refresh_token = NULL,
|
||||||
|
# OAuth2 auto refresh token
|
||||||
|
oauth_auto_refresh_token = FALSE,
|
||||||
# OAuth2
|
# OAuth2
|
||||||
# Flow type
|
# Flow type
|
||||||
oauth_flow_type = "implicit",
|
oauth_flow_type = "implicit",
|
||||||
@ -180,6 +183,7 @@ ApiClient <- R6::R6Class(
|
|||||||
# set the URL
|
# set the URL
|
||||||
req <- request(url)
|
req <- request(url)
|
||||||
|
|
||||||
|
# make the call via httr, which comes with retry logic
|
||||||
resp <- self$Execute(req, method, query_params, header_params, form_params,
|
resp <- self$Execute(req, method, query_params, header_params, form_params,
|
||||||
file_params, accepts, content_types, body, is_oauth = is_oauth,
|
file_params, accepts, content_types, body, is_oauth = is_oauth,
|
||||||
oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...)
|
oauth_scopes = oauth_scopes, stream_callback = stream_callback, ...)
|
||||||
@ -269,10 +273,10 @@ ApiClient <- R6::R6Class(
|
|||||||
req <- req %>% req_method(method)
|
req <- req %>% req_method(method)
|
||||||
|
|
||||||
# use oauth authentication if the endpoint requires it
|
# use oauth authentication if the endpoint requires it
|
||||||
if (is_oauth && !is.null(self$oauth_client_id) && !is.null(self$oauth_secret)) {
|
if (is_oauth && !is.null(self$oauth_client_id) && !is.null(self$oauth_client_secret)) {
|
||||||
client <- oauth_client(
|
client <- oauth_client(
|
||||||
id = self$oauth_client_id,
|
id = self$oauth_client_id,
|
||||||
secret = obfuscated(self$oauth_secret),
|
secret = obfuscated(self$oauth_client_secret),
|
||||||
token_url = self$oauth_token_url,
|
token_url = self$oauth_token_url,
|
||||||
name = "petstore-oauth"
|
name = "petstore-oauth"
|
||||||
)
|
)
|
||||||
|
@ -113,7 +113,7 @@ test_that("update_pet_with_form", {
|
|||||||
|
|
||||||
## update pet with form
|
## update pet with form
|
||||||
pet_api$api_client$oauth_client_id <- "client_id_aaa"
|
pet_api$api_client$oauth_client_id <- "client_id_aaa"
|
||||||
pet_api$api_client$oauth_secret <- "secrete_bbb"
|
pet_api$api_client$oauth_client_secret <- "secrete_bbb"
|
||||||
pet_api$api_client$oauth_scopes <- "write:pets read:pets"
|
pet_api$api_client$oauth_scopes <- "write:pets read:pets"
|
||||||
update_result <- pet_api$update_pet_with_form(update_pet_id, name = "pet2", status = "sold")
|
update_result <- pet_api$update_pet_with_form(update_pet_id, name = "pet2", status = "sold")
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#' @field api_keys API keys
|
#' @field api_keys API keys
|
||||||
#' @field access_token Access token
|
#' @field access_token Access token
|
||||||
#' @field oauth_client_id OAuth client ID
|
#' @field oauth_client_id OAuth client ID
|
||||||
#' @field oauth_secret OAuth secret
|
#' @field oauth_client_secret OAuth secret
|
||||||
#' @field oauth_refresh_token OAuth refresh token
|
#' @field oauth_refresh_token OAuth refresh token
|
||||||
#' @field oauth_flow_type OAuth flow type
|
#' @field oauth_flow_type OAuth flow type
|
||||||
#' @field oauth_authorization_url Authoriziation URL
|
#' @field oauth_authorization_url Authoriziation URL
|
||||||
@ -63,7 +63,7 @@ ApiClient <- R6::R6Class(
|
|||||||
# OAuth2 client ID
|
# OAuth2 client ID
|
||||||
oauth_client_id = NULL,
|
oauth_client_id = NULL,
|
||||||
# OAuth2 secret
|
# OAuth2 secret
|
||||||
oauth_secret = NULL,
|
oauth_client_secret = NULL,
|
||||||
# OAuth2 refresh token
|
# OAuth2 refresh token
|
||||||
oauth_refresh_token = NULL,
|
oauth_refresh_token = NULL,
|
||||||
# OAuth2
|
# OAuth2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user