Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to pass additional vars within authenticate? #625

Closed
fahadshery opened this issue Nov 8, 2019 · 4 comments
Closed

Question: how to pass additional vars within authenticate? #625

fahadshery opened this issue Nov 8, 2019 · 4 comments
Labels
feature a feature request or enhancement oauth 🏓

Comments

@fahadshery
Copy link

Probably not an issue but I have asked the question here

I have a weird api setting an additional static variable in the call grant_type=password. I am not sure how to pass it within authenticate method? any pointers would be helpful.

Ps I can authenticate using python without any issues

@cderv
Copy link
Contributor

cderv commented Nov 8, 2019

Hi,

From the API DOC your API is supporting Oauth2 authentication using Resource Owner Password Credentials Grant that uses grant_type = "password".

For Oauth2 API you would usually use httr::oauth2.0_token but currently, httr Oauht2 flow does not support this type of grant.

You would need to do it yourself.

From the doc (I did not try), you would need to use a POST with a body containing your parameter.

This should work:

username <- "my_username"
password <- "my_psw"
base_url = "https://api.checkbox.com/v1/my_account/oauth2/token"

response <- POST(url=base_url,
                 # pass data to the POST request
                 body = list(
                   username = username,
                   password = password,
                   grant_type = "password"
                 ),
                 # application/x-www-form-urlencoded
                 encode = "form",
                 verbose())

Can you check ?

@cderv
Copy link
Contributor

cderv commented Nov 8, 2019

related to #564 about the same type of grant

@hadley hadley added feature a feature request or enhancement oauth 🏓 labels Apr 3, 2020
@ponnet
Copy link

ponnet commented Apr 21, 2020

Thanks!
Not sure if it helps anyone but below yielded success with base_url being Authorize Endpoint:

response <- POST(url=base_url,
                 accept_json(),
                 body = list(
                   username = username,
                   password = password,
                   grant_type = "password"
                 ),
                 encode = "form",
                 verbose())

@hadley
Copy link
Member

hadley commented Oct 31, 2023

httr has been superseded in favour of httr2, so is no longer under active development. If this problem is still important to you in httr2, I'd suggest filing an issue offer there 😄 — but httr2 provides much stronger OAuth support and what you want is likely to be https://httr2.r-lib.org/dev/reference/req_oauth_password.html. Thanks for using httr!

@hadley hadley closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement oauth 🏓
Projects
None yet
Development

No branches or pull requests

4 participants