mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
add http bearer auth support to R client (#12974)
This commit is contained in:
parent
d1c2230709
commit
f26985c239
@ -97,11 +97,17 @@
|
||||
{{#authMethods}}
|
||||
#'
|
||||
{{#isBasic}}
|
||||
{{#isBasicBasic}}
|
||||
#' #Configure HTTP basic authorization: {{{name}}}
|
||||
#' # provide your username in the user-serial format
|
||||
#' api.instance$api_client$username <- '<user-serial>';
|
||||
#' # provide your api key generated using the developer portal
|
||||
#' api.instance$api_client$password <- '<api_key>';
|
||||
#' # provide the username
|
||||
#' api.instance$api_client$username <- 'TODO_YOUR_USERNAME';
|
||||
#' # provide the password
|
||||
#' api.instance$api_client$password <- 'TODO_YOUR_PASSWORD';
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}
|
||||
#' #Configure HTTP bearer authorization: {{{name}}}
|
||||
#' api.instance$api_client$bearer_token <- 'TODO_YOUR_BEARER_TOKEN';
|
||||
{{/isBasicBearer}}
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
#' #Configure API key authorization: {{{name}}}
|
||||
@ -302,6 +308,9 @@
|
||||
# HTTP basic auth
|
||||
header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}
|
||||
header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
|
||||
{{/isBasicBearer}}
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
# API key authentication
|
||||
|
@ -22,6 +22,7 @@
|
||||
#' @field password Password for HTTP basic authentication
|
||||
#' @field api_keys API keys
|
||||
#' @field access_token Access token
|
||||
#' @field bearer_token Bearer token
|
||||
#' @field timeout Default timeout in seconds
|
||||
#' @field retry_status_codes vector of status codes to retry
|
||||
#' @field max_retry_attempts maximum number of retries for the status codes
|
||||
@ -47,6 +48,8 @@ ApiClient <- R6::R6Class(
|
||||
api_keys = NULL,
|
||||
# Access token
|
||||
access_token = NULL,
|
||||
# Bearer token
|
||||
bearer_token = NULL,
|
||||
# Time Out (seconds)
|
||||
timeout = NULL,
|
||||
# Vector of status codes to retry
|
||||
@ -65,6 +68,7 @@ ApiClient <- R6::R6Class(
|
||||
#' @param password Password.
|
||||
#' @param api_keys API keys.
|
||||
#' @param access_token Access token.
|
||||
#' @param bearer_token Bearer token.
|
||||
#' @param timeout Timeout.
|
||||
#' @param retry_status_codes Status codes for retry.
|
||||
#' @param max_retry_attempts Maxmium number of retry.
|
||||
@ -72,7 +76,7 @@ ApiClient <- R6::R6Class(
|
||||
initialize = function(base_path = NULL, user_agent = NULL,
|
||||
default_headers = NULL,
|
||||
username = NULL, password = NULL, api_keys = NULL,
|
||||
access_token = NULL, timeout = NULL,
|
||||
access_token = NULL, bearer_token = NULL, timeout = NULL,
|
||||
retry_status_codes = NULL, max_retry_attempts = NULL) {
|
||||
if (!is.null(base_path)) {
|
||||
self$base_path <- base_path
|
||||
@ -94,6 +98,10 @@ ApiClient <- R6::R6Class(
|
||||
self$access_token <- access_token
|
||||
}
|
||||
|
||||
if (!is.null(bearer_token)) {
|
||||
self$bearer_token <- bearer_token
|
||||
}
|
||||
|
||||
if (!is.null(api_keys)) {
|
||||
self$api_keys <- api_keys
|
||||
} else {
|
||||
|
@ -32,9 +32,15 @@ api_instance <- {{{classname}}}$new()
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
{{#isBasicBasic}}
|
||||
# Configure HTTP basic authorization: {{{name}}}
|
||||
api_instance$api_client$username <- 'TODO_YOUR_USERNAME';
|
||||
api_instance$api_client$password <- 'TODO_YOUR_PASSWORD';
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}
|
||||
# Configure HTTP bearer authorization: {{{name}}}
|
||||
api.instance$api_client$bearer_token <- 'TODO_YOUR_BEARER_TOKEN';
|
||||
{{/isBasicBearer}}
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
# Configure API key authorization: {{{name}}}
|
||||
|
@ -184,7 +184,7 @@ paths:
|
||||
'404':
|
||||
description: Pet not found
|
||||
security:
|
||||
- api_key: []
|
||||
- BearerToken: []
|
||||
'/pet/{petId}?streaming':
|
||||
get:
|
||||
tags:
|
||||
@ -671,6 +671,9 @@ components:
|
||||
description: Pet object that needs to be added to the store
|
||||
required: true
|
||||
securitySchemes:
|
||||
BearerToken:
|
||||
type : http
|
||||
scheme : bearer
|
||||
petstore_auth:
|
||||
type: oauth2
|
||||
flows:
|
||||
|
@ -29,6 +29,7 @@
|
||||
#' @field password Password for HTTP basic authentication
|
||||
#' @field api_keys API keys
|
||||
#' @field access_token Access token
|
||||
#' @field bearer_token Bearer token
|
||||
#' @field timeout Default timeout in seconds
|
||||
#' @field retry_status_codes vector of status codes to retry
|
||||
#' @field max_retry_attempts maximum number of retries for the status codes
|
||||
@ -52,6 +53,8 @@ ApiClient <- R6::R6Class(
|
||||
api_keys = NULL,
|
||||
# Access token
|
||||
access_token = NULL,
|
||||
# Bearer token
|
||||
bearer_token = NULL,
|
||||
# Time Out (seconds)
|
||||
timeout = NULL,
|
||||
# Vector of status codes to retry
|
||||
@ -70,6 +73,7 @@ ApiClient <- R6::R6Class(
|
||||
#' @param password Password.
|
||||
#' @param api_keys API keys.
|
||||
#' @param access_token Access token.
|
||||
#' @param bearer_token Bearer token.
|
||||
#' @param timeout Timeout.
|
||||
#' @param retry_status_codes Status codes for retry.
|
||||
#' @param max_retry_attempts Maxmium number of retry.
|
||||
@ -77,7 +81,7 @@ ApiClient <- R6::R6Class(
|
||||
initialize = function(base_path = NULL, user_agent = NULL,
|
||||
default_headers = NULL,
|
||||
username = NULL, password = NULL, api_keys = NULL,
|
||||
access_token = NULL, timeout = NULL,
|
||||
access_token = NULL, bearer_token = NULL, timeout = NULL,
|
||||
retry_status_codes = NULL, max_retry_attempts = NULL) {
|
||||
if (!is.null(base_path)) {
|
||||
self$base_path <- base_path
|
||||
@ -99,6 +103,10 @@ ApiClient <- R6::R6Class(
|
||||
self$access_token <- access_token
|
||||
}
|
||||
|
||||
if (!is.null(bearer_token)) {
|
||||
self$bearer_token <- bearer_token
|
||||
}
|
||||
|
||||
if (!is.null(api_keys)) {
|
||||
self$api_keys <- api_keys
|
||||
} else {
|
||||
|
@ -373,8 +373,8 @@
|
||||
#' #Find pet by ID
|
||||
#' api.instance <- PetApi$new()
|
||||
#'
|
||||
#' #Configure API key authorization: api_key
|
||||
#' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
|
||||
#' #Configure HTTP bearer authorization: BearerToken
|
||||
#' api.instance$api_client$bearer_token <- 'TODO_YOUR_BEARER_TOKEN';
|
||||
#'
|
||||
#'result <- tryCatch(
|
||||
#' api.instance$GetPetById(var.pet_id),
|
||||
@ -969,10 +969,7 @@ PetApi <- R6::R6Class(
|
||||
url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), url_path)
|
||||
}
|
||||
|
||||
# API key authentication
|
||||
if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
|
||||
header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
|
||||
}
|
||||
header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
|
||||
|
||||
resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
|
||||
method = "GET",
|
||||
|
@ -111,6 +111,10 @@ Class | Method | HTTP request | Description
|
||||
## Documentation for Authorization
|
||||
|
||||
|
||||
### BearerToken
|
||||
|
||||
- **Type**: HTTP basic authentication
|
||||
|
||||
### api_key
|
||||
|
||||
- **Type**: API key
|
||||
|
@ -271,8 +271,8 @@ var_pet_id <- 56 # integer | ID of pet to return
|
||||
|
||||
#Find pet by ID
|
||||
api_instance <- PetApi$new()
|
||||
# Configure API key authorization: api_key
|
||||
api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
|
||||
# Configure HTTP bearer authorization: BearerToken
|
||||
api.instance$api_client$bearer_token <- 'TODO_YOUR_BEARER_TOKEN';
|
||||
result <- tryCatch(
|
||||
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
|
||||
# api_instance$GetPetById(var_pet_id, data_file = "result.txt"),
|
||||
@ -304,7 +304,7 @@ Name | Type | Description | Notes
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
[BearerToken](../README.md#BearerToken)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user