title: OAuth2 authentication with R using httr
body: <p>I am trying to read some data from the Polar Accesslink API. I have read the documentation and examples (I'm not that familiar with Python) as well as httr examples/demos of Oauth2.0:</p>
  <p><a href="https://www.polar.com/accesslink-api/#polar-accesslink-api" rel="nofollow noreferrer">https://www.polar.com/accesslink-api/#polar-accesslink-api</a></p>
  <p><a href="https://github.com/polarofficial/accesslink-example-python" rel="nofollow noreferrer">https://github.com/polarofficial/accesslink-example-python</a></p>
  <p>Here is my code:</p>
  <pre><code>library(httr)
  
  client_id &lt;- rstudioapi::askForPassword()
  
  client_secret &lt;- rstudioapi::askForPassword()
  
  # redirect_uri determined in registration to http://localhost:1410/
  
  app &lt;- oauth_app(appname = &quot;polar_app&quot;,
                   key = client_id,
                   secret = client_secret)
  
  endpoint &lt;- oauth_endpoint(
    request = NULL,
    authorize = &quot;https://flow.polar.com/oauth2/authorization&quot;,
    access = &quot;https://polarremote.com/v2/oauth2/token&quot;)
  
  
  token &lt;- oauth2.0_token(endpoint = endpoint,
                          app = app,
                          scope = &quot;accesslink.read_all&quot;, # tested also without scope
                          use_basic_auth = T # tested both T and F
                          )
  </code></pre>
  <p>Last part of the code (token) produces the following error:</p>
  <pre><code>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.
  </code></pre>
  <p>It opens browser with url localhost:1410/?state={STATE}&amp;code={CODE} and says:</p>
  <p>&quot;Authentication complete. Please close this page and return to R.&quot;</p>
  <p>Based on the 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.</p>