Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

OAuth2 authentication with R using httr

$
0
0

I am trying to read some data from Polar Accesslink API. I have read their documentation and examples (Python, not that familiar with it) as well as httr examples/demos of Oauth2.0:

https://www.polar.com/accesslink-api/#polar-accesslink-api

https://github.com/polarofficial/accesslink-example-python

Here is my code:

library(httr)

client_id <- rstudioapi::askForPassword()

client_secret <- rstudioapi::askForPassword()

# redirect_uri determined in registration to http://localhost:1410/

app <- oauth_app(appname = "polar_app",
                 key = client_id,
                 secret = client_secret)

endpoint <- oauth_endpoint(
  request = NULL,
  authorize = "https://flow.polar.com/oauth2/authorization",
  access = "https://polarremote.com/v2/oauth2/token")


token <- oauth2.0_token(endpoint = endpoint,
                        app = app,
                        scope = "accesslink.read_all", # tested also without scope
                        use_basic_auth = T # tested both T and F
                        )

Last part of the code (token) produces the following error:

Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Bad Request (HTTP 400). Failed to get an access token.

It opens browser with url localhost:1410/?state={STATE}&code={CODE} and says:

"Authentication complete. Please close this page and return to R."

Based on API documentation and github Python examples, I can't figure out if I need to set some values for user_params or query_authorize_extra in oauth2.0_token.


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>