4040# ' @examples
4141# ' oauth_client("myclient", "http://example.com/token_url", secret = "DONTLOOK")
4242oauth_client <- function (
43- id ,
44- token_url ,
45- secret = NULL ,
46- key = NULL ,
47- auth = c(" body" , " header" , " jwt_sig" ),
48- auth_params = list (),
49- name = hash(id )
50- ) {
51-
43+ id ,
44+ token_url ,
45+ secret = NULL ,
46+ key = NULL ,
47+ auth = c(" body" , " header" , " jwt_sig" ),
48+ auth_params = list (),
49+ name = hash(id )
50+ ) {
5251 check_string(id )
5352 check_string(token_url )
5453 check_string(secret , allow_null = TRUE )
@@ -66,7 +65,9 @@ oauth_client <- function(
6665 cli :: cli_abort(" {.code auth = 'jwt_sig'} requires a {.arg key}." )
6766 }
6867 if (! has_name(auth_params , " claim" )) {
69- cli :: cli_abort(" {.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}." )
68+ cli :: cli_abort(
69+ " {.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}."
70+ )
7071 }
7172 }
7273
@@ -167,7 +168,8 @@ oauth_client_req_auth <- function(req, client) {
167168# ' @export
168169# ' @rdname oauth_client_req_auth
169170oauth_client_req_auth_header <- function (req , client ) {
170- req_auth_basic(req ,
171+ req_auth_basic(
172+ req ,
171173 username = client $ id ,
172174 password = unobfuscate(client $ secret )
173175 )
@@ -176,7 +178,8 @@ oauth_client_req_auth_header <- function(req, client) {
176178# ' @export
177179# ' @rdname oauth_client_req_auth
178180oauth_client_req_auth_body <- function (req , client ) {
179- req_body_form(req ,
181+ req_body_form(
182+ req ,
180183 client_id = client $ id ,
181184 client_secret = unobfuscate(client $ secret ) # might be NULL
182185 )
@@ -185,24 +188,33 @@ oauth_client_req_auth_body <- function(req, client) {
185188# ' @inheritParams jwt_claim
186189# ' @export
187190# ' @rdname oauth_client_req_auth
188- oauth_client_req_auth_jwt_sig <- function (req , client , claim , size = 256 , header = list ()) {
191+ oauth_client_req_auth_jwt_sig <- function (
192+ req ,
193+ client ,
194+ claim ,
195+ size = 256 ,
196+ header = list ()
197+ ) {
189198 claim <- exec(" jwt_claim" , !!! claim )
190199 jwt <- jwt_encode_sig(claim , key = client $ key , size = size , header = header )
191200
192201 # https://datatracker.ietf.org/doc/html/rfc7523#section-2.2
193- req_body_form(req ,
202+ req_body_form(
203+ req ,
194204 client_assertion = jwt ,
195205 client_assertion_type = " urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
196206 )
197207}
198208
199209# Helpers -----------------------------------------------------------------
200210
201- oauth_flow_check <- function (flow , client ,
202- is_confidential = FALSE ,
203- interactive = FALSE ,
204- error_call = caller_env()) {
205-
211+ oauth_flow_check <- function (
212+ flow ,
213+ client ,
214+ is_confidential = FALSE ,
215+ interactive = FALSE ,
216+ error_call = caller_env()
217+ ) {
206218 if (! inherits(client , " httr2_oauth_client" )) {
207219 cli :: cli_abort(
208220 " {.arg client} must be an OAuth client created with {.fn oauth_client}." ,
@@ -228,10 +240,12 @@ oauth_flow_check <- function(flow, client,
228240 }
229241}
230242
231- oauth_client_get_token <- function (client ,
232- grant_type ,
233- ... ,
234- error_call = caller_env()) {
243+ oauth_client_get_token <- function (
244+ client ,
245+ grant_type ,
246+ ... ,
247+ error_call = caller_env()
248+ ) {
235249 req <- request(client $ token_url )
236250 req <- req_body_form(req , grant_type = grant_type , ... )
237251 req <- oauth_client_req_auth(req , client )
0 commit comments