-
Notifications
You must be signed in to change notification settings - Fork 2k
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
OAuth 2.0 resource owner authentication #564
Comments
There is a What you linked to is specific to Resource Owner Password Credentials Grant and may need a Do you have an API in mind so that this could be tested further ? it would help to have an example of such an api. thanks! |
Yes, the |
Ok, so if you tried, with which API ? |
By the cunning stratagem of reading the source, I have determined that httr does not support this. |
So this is a feature request. I really thing that already all the tools are there to make it work, and there is not so much to do to support this grant. I built a dummy example using url <- "https://httpbin.org/post"
library(httr)
api_endpoint <- oauth_endpoint(
authorize = NULL,
access = "https://httpbin.org/post" # for demo
)
api_app <- oauth_app(
appname = "app_dummy",
key = "clientid",
secret = "clientsecret"
)
json_res <- oauth2.0_access_token(
endpoint = api_endpoint,
app = api_app,
user_params = list(grant_type = "password", username = "username", password = "password"),
code = NULL,
use_basic_auth = TRUE,
type = "text"
)
#> No encoding supplied: defaulting to UTF-8.
jsonlite::prettify(json_res)
#> {
#> "args": {
#>
#> },
#> "data": "",
#> "files": {
#>
#> },
#> "form": {
#> "client_id": "clientid",
#> "grant_type": "authorization_code",
#> "password": "password",
#> "redirect_uri": "http://localhost:1410/",
#> "username": "username"
#> },
#> "headers": {
#> "Accept": "application/json, text/xml, application/xml, */*",
#> "Accept-Encoding": "gzip, deflate",
#> "Authorization": "Basic Y2xpZW50aWQ6Y2xpZW50c2VjcmV0",
#> "Connection": "close",
#> "Content-Length": "130",
#> "Content-Type": "application/x-www-form-urlencoded",
#> "Host": "httpbin.org",
#> "User-Agent": "libcurl/7.59.0 r-curl/3.2 httr/1.4.0"
#> },
#> "json": null,
#> "origin": "176.183.22.128",
#> "url": "https://httpbin.org/post"
#> }
#> In all case it should work using a POST call that will return you the token in response. res <- POST(url,
body = list(grant_type = "password", username = "username", password = "password"),
authenticate("clientid", "clientsecret"),
encode = "form"
)
jsonlite::prettify(content(res, "text"))
#> No encoding supplied: defaulting to UTF-8.
#> {
#> "args": {
#>
#> },
#> "data": "",
#> "files": {
#>
#> },
#> "form": {
#> "grant_type": "password",
#> "password": "password",
#> "username": "username"
#> },
#> "headers": {
#> "Accept": "application/json, text/xml, application/xml, */*",
#> "Accept-Encoding": "gzip, deflate",
#> "Authorization": "Basic Y2xpZW50aWQ6Y2xpZW50c2VjcmV0",
#> "Connection": "close",
#> "Content-Length": "55",
#> "Content-Type": "application/x-www-form-urlencoded",
#> "Host": "httpbin.org",
#> "User-Agent": "libcurl/7.59.0 r-curl/3.2 httr/1.4.0"
#> },
#> "json": null,
#> "url": "https://httpbin.org/post"
#> }
#> So I think this 📦 allows it to work, but not supported in an httr oauth dance flow yet, but could easily be. However, I don't have example to test to see how an API of this type respond. Hope it helps. |
Anyway, this is now implemented in AzureRMR along with device code auth: https://github.com/cloudyr/AzureRMR/blob/master/R/AzureToken.R Feel free to steal implementation details for httr/httr2. Caveat: not heavily tested yet. |
From the code you linked to, you used a function to wrap the For reference as it is not precise, the example API is Azure which have several auth mechanisms, including resource owner grant type and it has been implemented in cloudyr/AzureRMR#5 |
Implemented in httr2: https://httr2.r-lib.org/reference/req_oauth_password.html |
(As opposed to http basic authentication, which is what
authenticate
does.)Does httr support this? This is authenticating via a username and password, as opposed to a client secret:
https://tools.ietf.org/html/rfc6749#section-4.3.2
The text was updated successfully, but these errors were encountered: