Hi all, I've done some experimentation in plumber and trying to integrate Azure OAuth2 using an authorization code, with the eventual goal of releasing this to RStudio Connect. I am having problems having the redirect in plumber go to the correct place on my local machine, which is also the same issue in RStudio Connect.
Presently, I have basic entrypoint.R file, where the <TENANT_ID> is the my Azure tenant guid:
# entrypoint.R
library(plumber)
pr$setApiSpec(function(spec) {
spec$info$title <- "Test"
spec$openid <- "3.0.3"
spec$components$securitySchemes$azureoauth$type <- 'oauth2'
spec$components$securitySchemes$azureoauth$description <- 'API key to authorize requests.'
spec$components$securitySchemes$azureoauth$flows$authorizationCode$authorizationUrl <- 'https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/authorize'
spec$components$securitySchemes$azureoauth$flows$authorizationCode$tokenUrl <- 'https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token'
spec$components$securitySchemes$azureoauth$flows$authorizationCode$scopes$`https://graph.microsoft.com/User.Read` <- 'Sign in and read user profile'
spec
})
And a vanilla plumber.R
file that does nothing with it (just a literal)
# plumber.R
#* @get /hello
function(req) {
print('hello')
}
I am able to get the authorization button and the authorizations modal to open up:
And I can click on the Authorization button and go to Azure and authorize the user. Where I run into trouble is the redirect/reply url. After it gets a code, its coming back to a 404 page that doesn't seem to exist in the root at http://localhost:8100/oauth2-redirect.html
Secondary issues:
- I'd like to specify the client_id and client_secret by default somewhere, but I'm not sure where to put it.
- When I deploy to RStudio Connect, the redirect goes to
http://rstudioconnect.company.com/oauth2-redirect.html
, versus the app itselfhttp://rstudioconnect.company.com/appname/oauth2-redirect.html
. I suspect this challenge is related to the above.
Some preliminary research indicates a callback/redirect, but not entirely sure how to pass that off (as referenced here). Does anyone have any pointers or guidance?
Thanks,
Jon