When Workbench is using Azure Active Directory for sign-in, this function can return an OAuth2 token for a service Workbench users have delegated access to. This requires configuring delegated permissions in Azure itself.

getDelegatedAzureToken(resource, as = c("list", "AzureToken"))

Arguments

resource

The name of an Azure resource or service, normally a URL.

as

The form of the returned token. "list" (the default) returns a plain list of OAuth2 token details. "AzureToken" returns an R6 object compatible with the AzureToken class from the AzureAuth package, so it can be passed directly to packages like AzureGraph and Microsoft365R. The R6 package must be installed for this option.

Value

When as = "list", a list containing the OAuth2 token details, including the fields access_token, token_type, scope, and expires_at (the expiry time, in seconds since the Unix epoch). When as = "AzureToken", an R6 object of class AzureToken wrapping the same details, with a refresh() method that requests a new delegated token from Workbench. Throws an error if a token is unavailable.

Examples

if (FALSE) { # \dontrun{
getDelegatedAzureToken("https://storage.azure.com")

# Authenticate with Microsoft Graph using AzureGraph / Microsoft365R
token <- getDelegatedAzureToken("https://graph.microsoft.com/", as = "AzureToken")
gr <- AzureGraph::ms_graph$new(token = token)
site <- Microsoft365R::get_sharepoint_site(
  site_url = "https://example.sharepoint.com/sites/my-site",
  token = token
)
} # }