I am trying to access the domain.com.au api using r and httr. I can achieve this using an API key but not with OAuth2
The docs indicate that:
Obtaining an access token via Client Credentials Make a POST request to the https://auth.domain.com.au/v1/connect/token endpoint using your client_id and client_secret, along with the list of scopes that you require. See the API references for the list of scopes that are required for each endpoint. Attempting to use a scope that is not included in your plan will result in a 400 invalid_scope error. This request must be authenticated using basic authentication with the client_id and client_secret corresponding to a username and password respectively.
https://developer.domain.com.au/docs/v2/authentication/oauth/client-credentials-grant
The curl implementation is simply:
curl -X POST -u 'clientid:secret' -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=client_credentials&scope=api_listings_read%20api_agencies_read' 'https://auth.domain.com.au/v1/connect/token'
which returns the token without any redirect.
However, I have been unable to translate this to the equivalent httr POST request to obtain the token. What I presently have is:
oep <- oauth_endpoint(base_url = "https://auth.domain.com.au/v1/connect/token",
request = NULL,
access = "access_token" )
myapp <- oauth_app("domain",
key = "client_id_here",
# The secret isn't secrete. A user still has to authenticate when redirected.
secret = "secret_here"
)
# Retrieve the token
token <- oauth2.0_token(oep,
myapp,
scope = "api_listings_read")
This unnecessarily redirects to an unknown page, which I close and then am returned to the console where I press escape to exit.
I am reviewing Converting cURL to httr in R but so far no luck in getting it to work.
Any help would be much appreciated.