Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
308 stars 42 forks source link

Struggling with authentication while running on Databricks #136

Closed nBhabish closed 1 year ago

nBhabish commented 1 year ago

I am trying to automate one of my R scripts that will be sending out weekly emails to my external stakeholders, but I am struggling with the authentication piece. I was wondering if someone could help me with this

Web capture_1-11-2022_92432_adb-6816676953916991 11 azuredatabricks net

hongooi73 commented 1 year ago

When authenticating on Databricks or any other environment where you're in a shell, you have to use the device_code flow.

get_business_outlook(app="xxx", auth_type="device_code")
nBhabish commented 1 year ago

@hongooi73 if you don't mind me asking, what exactly is a device_code? Also, where can I find it/ how do I find it?

nBhabish commented 1 year ago

@hongooi73 how do I get the azure login creds to be saved in Databricks? Every time the script is scheduled to run it will eventually come to a point where I'll have to go and authenticate it manually. I was wondering if there's a way for it to be a one-time thing in Databricks if that makes sense. It says the following: AzureR data directory does not exist; login credentials not saved image

hongooi73 commented 1 year ago

You can create the directory it's looking for with dir.create(AzureAuth::AzureR_dir()). I'm not that familiar with Databricks but I assume the node you're running this on is persistent, so the dir should stick around between sessions.

nBhabish commented 1 year ago

@hongooi73 I think this might help me a great deal. I was able to create a custom app registration and use create_graph_login to authenticate to Azure in an unattended script to automate sending emails. However, I can't pull my outlook credentials using get_business_outlook() in that unattended script. I was wondering if you could help me figure out a way to pull my outlook credentials after the graph login.

hongooi73 commented 1 year ago

Technically you can use auth_type="resource_owner" to authenticate a user account in an unattended script. See the vignettes for the AzureAuth package. This is discouraged however, and your org may also have disabled it.

More info: https://learn.microsoft.com/en-au/azure/active-directory/develop/v2-oauth-ropc