Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
318 stars 45 forks source link

Authentication when deployed on shinyapps.io #79

Closed jadelhoss closed 3 years ago

jadelhoss commented 3 years ago

Hi there,

Thanks for putting this package together, it has been long awaited and I am really excited to be able to leverage it.

I am trying to build a Shiny app to deploy on shinapps.io. BUT I cannot get the authentication to work. Calling get_business_onedrive() works when I have the local token on my computer, but nothing happens when deployed on shinyapps.io.

I played around with AzureAuth :: build_authorization_uri(), but I am not comfortable building my own authentication pipeline. The default values in get_business_onedrive() worked fine when run locally, can we replicate it when deployed online?

The behavior I am after is that on loading the app, the users are immediately asked to login with the M365 credentials. I can then load shared data that is stored in OneDrive/Sharepoint and start to run the analytics.

Any help would be greatly appreciated.

Thanks in advance, Jad

hongooi73 commented 3 years ago

This is the 3rd time I've been asked this same basic question, I think I'm going to have to get off my butt and write a vignette, lol.

You have to register your app with Azure, there is no getting around it. The builtin MS365R app registration assumes it's being run on the local machine, so it won't work if the code is on a remote server.

The process is:

jadelhoss commented 3 years ago

OK great.

Thanks for the prompt reply. I have registered my app and now will work through this.

Cheers, Jad

hongooi73 commented 3 years ago

I have a draft vignette written up in the shiny-auth branch: https://github.com/Azure/Microsoft365R/blob/shiny-auth/vignettes/shiny.Rmd

Comments appreciated.

@agerns

jadelhoss commented 3 years ago

Thanks Hong for the prompt Vignette.

I worked through your Azure Auth Shiny Vignette, and managed to get as far as logging into with Microsoft from my app (well, your vignette app really with my app details), and then get redirected to my app. Very encouraging start.

For some reason though I am immediately disconnected from the shinyapps.io server (ie. I get the greyed out screen from shinyapp.io with message 'Disconnect from Server' on the bottom left). Looking at this vignette, very similar, so maybe I need to tweak a parameter. But if I am getting passed Microsoft an into shinyapps, so must be something to do with the server code? I won't bother sharing code, as it's exactly as your vignette, only I added the pwd argument for client secret. What could cause immediate disconnect from shinyapps.io once I am redirected?

As always, thanks for any help, I have been looking forward to this package for a long time.

Cheers, Jad

hongooi73 commented 3 years ago

It works when I run it locally. I haven't used shinyapps.io, but you should be able to see what the error log contains:

https://docs.rstudio.com/shinyapps.io/Troubleshooting.html#disconnected-from-server-messages

hongooi73 commented 3 years ago

The example app should work in Shinyapps.io now. Ping me if you're still having problems.

@jadelhoss @agerns

agerns commented 3 years ago

Thanks Hong for so quickly rewriting the vignette. I had also some issues in the first draft of the vignette that now seem to be fixed. The authentication and access to, in my case, Sharepoint work great! Thank you so much for this!!