Login clients for Microsoft 365
Microsoft365R provides functions for logging into each Microsoft 365 service.
get_personal_onedrive( app = .microsoft365r_app_id, scopes = c("Files.ReadWrite.All", "User.Read"), ... ) get_business_onedrive( tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... ) get_sharepoint_site( site_name = NULL, site_url = NULL, site_id = NULL, tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... ) list_sharepoint_sites( tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... ) get_team( team_name = NULL, team_id = NULL, tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... ) list_teams( tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... ) get_personal_outlook( app = .microsoft365r_app_id, scopes = c("Mail.Send", "Mail.ReadWrite", "User.Read"), ... ) get_business_outlook( tenant = Sys.getenv("CLIMICROSOFT365_TENANT", "common"), app = Sys.getenv("CLIMICROSOFT365_AADAPPID"), scopes = ".default", ... )
app |
A custom app registration ID to use for authentication. See below. |
scopes |
The Microsoft Graph scopes (permissions) to obtain. It should never be necessary to change these. |
... |
Optional arguments that will ultimately be passed to |
tenant |
For |
site_name, site_url, site_id |
For |
team_name, team_id |
For |
These functions provide easy access to the various collaboration services that are part of Microsoft 365. On first use, they will call your web browser to authenticate with Azure Active Directory, in a similar manner to other web apps. You will get a dialog box asking for permission to access your information. You only have to authenticate once; your credentials will be saved and reloaded in subsequent sessions.
When authenticating, you can pass optional arguments in ...
which will ultimately be received by AzureAuth::get_azure_token
. In particular, if your machine doesn't have a web browser available to authenticate with (for example if you are in a remote RStudio Server session), pass auth_type="device_code"
which is intended for such scenarios.
For get_personal_onedrive
and get_business_onedrive
, an R6 object of class ms_drive
.
For get_sharepoint_site
, an R6 object of class ms_site
; for list_sharepoint_sites
, a list of such objects.
For get_team
, an R6 object of class ms_team
; for list_teams
, a list of such objects.
Authenticating to Microsoft 365 Business services (Teams, SharePoint and OneDrive for Business) has some specific complexities.
The default "common" tenant for get_team
, get_business_onedrive
and get_sharepoint_site
attempts to detect your actual tenant from your saved credentials in your browser. This may not always succeed, for example if you have a personal account that is also a guest account in a tenant. In this case, supply the actual tenant name, either in the tenant
argument or in the CLIMICROSOFT365_TENANT
environment variable. The latter allows sharing authentication details with the CLI for Microsoft 365.
The default when authenticating to these services is for Microsoft365R to use its own internal app ID. As an alternative, you (or your admin) can create your own app registration in Azure: it should have a native redirect URI of http://localhost:1410
, and the "public client" option should be enabled if you want to use the device code authentication flow. You can supply your app ID either via the app
argument, or in the environment variable CLIMICROSOFT365_AADAPPID
.
add_methods
for the associated methods that this package adds to the base AzureGraph classes.
The "Authentication" vignette has more details on the authentication process, including troubleshooting and fixes for common problems.
CLI for Microsoft 365 – a commandline tool for managing Microsoft 365
## Not run: get_personal_onedrive() # authenticating without a browser get_personal_onedrive(auth_type="device_code") odb <- get_business_onedrive("mycompany") odb$list_items() mysite <- get_sharepoint_site("My site", tenant="mycompany") mysite <- get_sharepoint_site(site_url="https://mycompany.sharepoint.com/sites/my-site-url") mysite$get_drive()$list_items() myteam <- get_team("My team", tenant="mycompany") myteam$list_channels() myteam$get_drive()$list_items() # you can also use your own app registration ID: get_business_onedrive(app="app_id") get_sharepoint_site("My site", app="app_id") # using the app ID for the CLI for Microsoft 365: set a global option options(microsoft365r_use_cli_app_id=TRUE) get_business_onedrive() get_sharepoint_site("My site") get_team("My team") ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.