I use the code below to get API access to my Microsoft Dynamics Environment where data is stored.
require(httr)
dataverse_api = oauth_endpoint(request = NULL,
authorize = "https://login.microsoftonline.com/[REDACTED]/oauth2/v2.0/authorize",
access = "https://login.microsoftonline.com/[REDACTED]/oauth2/v2.0/token",
base_url = "https://login.microsoftonline.com/common/oauth2/authorize?resource=https://[REDACTED].crm4.dynamics.com")
API.Key = "[REDACTED]"
API.Secret = "[REDACTED]"
App = oauth_app("[REDACTED]", key = API.Key, secret = API.Secret)
API.token = oauth2.0_token(dataverse_api, App, scope = "https://[REDACTED].crm4.dynamics.com/user_impersonation", cache = FALSE, use_oob = FALSE)
API.AuthKey = API.token$credentials$access_token
If I run the code in RStudio, it points my browser to a URL and I get the response:
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete
However, if I run the code in the R Terminal, it returns the URL into the R Terminal that I then need to copy and paste into the browser to complete the authentication.
What I want to know is... what is RStudio doing to automate this step? How does RStudio know the URL to open? How can I extract that URL and put it into a browseURL function to automate this last step? Here is what I've tried...
- I've looked through all of the parameters of my API.token by typing
API.token$and continuing down the path to explore things likecache_path,private_key,endpoint$authorize,params$.... In all of these parameters I haven't found anything that matches the URL that gets opened in my web browser from RStudio. - I've tried setting
use_oob=TRUE, but this actually provides a 400-type response. - I've looked through
?oauth2.0_tokenand the link toToken()provided in the Details section, which I didn't find helpful.
I'm expecting that somewhere there is a parameter that I can extract and put it into a code like this:
browseURL(paste("http://localhost:1410/?code=","INSERT PARAMETER HERE",sep = ""))
Does anyone know how to get that parameter?