0

My question is closely related to this one: R httr Linkedin API: Bad Request (HTTP 400).

I have an application set up in Azure AD that I would like to use to get data out of MS Dataverse using R. I am new to APIs, so I first set it up in Postman. I was successful at getting to my data in Postman, but it did not require a Scope parameter.

I attempted to recreate what I did in Postman in R...

require(rvest)

dataverse_api = oauth_endpoint(request = NULL, 
   authorize = "REDACTED",
   access = "REDACTED",
   base_url = "REDACTED")

API.Key = "REDACTED"
API.Secret = "REDACTED"

App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)

API.token = oauth2.0_token(dataverse_api, App)

This caused my browser to open and give me an error saying a scope was required. I have been searching through documentation to find nomenclature for scopes, but haven't been successful. I have found several documents (1, 2, etc.) that are somewhat peripheral that list options such as "ReadWrite.All" or "Files.ReadWrite.All", but my understanding is that these are permissions which are different from Scope. Because I don't know what I'm doing, I tried several of them as such:

require(rvest)

dataverse_api = oauth_endpoint(request = NULL, 
   authorize = "REDACTED",
   access = "REDACTED",
   base_url = "REDACTED")

API.Key = "REDACTED"
API.Secret = "REDACTED"

App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)

API.token = oauth2.0_token(dataverse_api, App, scope = "User_impersonation")

The result is always the same. The browser opens with a message Authentication complete. Please close this page and return to R., but in R I get:

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.

From the link I cited above as being a similar question, I understand that I am still missing the Scope parameter. But I do not know where to get the Scope parameter for MS Dataverse. Can anyone help with this?

SIE_Vict0ria
  • 174
  • 1
  • 10
  • You should try to ask for the openid scope as well, does that help? – Tore Nestenius Dec 01 '21 at 07:56
  • Thanks for your response. I am unfamiliar with that term. What is an openid scope? And who do I ask for that? – SIE_Vict0ria Dec 01 '21 at 10:34
  • 1
    scopes are what you are trying to get access to, if you want to authenticate with AzureAD I think you need to add the openid scope as wel, see https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent – Tore Nestenius Dec 01 '21 at 10:44

1 Answers1

0

I don't know if there are other options, but in case it's helpful to anyone else I was able to make it work by specifying the scope as the Dynamics 365 URL followed by .default. For me this looks like: https://org593dc393.crm4.dynamics.com/.default

SIE_Vict0ria
  • 174
  • 1
  • 10