Skip to contents

Creates a token provider function that retrieves authentication credentials and returns a callable token getter. This function handles the credential discovery process and returns the token acquisition method from the discovered credential object.

Usage

get_token_provider(
  scope = NULL,
  tenant_id = NULL,
  client_id = NULL,
  client_secret = NULL,
  use_cache = "disk",
  offline = FALSE,
  .chain = default_credential_chain(),
  .verbose = FALSE
)

Arguments

scope

Optional character string specifying the authentication scope.

tenant_id

Optional character string specifying the tenant ID for authentication.

client_id

Optional character string specifying the client ID for authentication.

client_secret

Optional character string specifying the client secret for authentication.

use_cache

Character string indicating the caching strategy. Defaults to "disk". Options include "disk" for disk-based caching or "memory" for in-memory caching.

offline

Logical. If TRUE, operates in offline mode. Defaults to FALSE.

.chain

A list of credential objects, where each element must inherit from the Credential base class. Credentials are attempted in the order provided until get_token succeeds.

.verbose

Logical. If TRUE, prints detailed diagnostic information during credential discovery and authentication. Defaults to FALSE.

Value

A function that retrieves and returns an authentication token when called.

Examples

# In non-interactive sessions, this function will return an error if the
# environment is not set up with valid credentials. In an interactive session
# the user will be prompted to attempt one of the interactive authentication flows.
if (FALSE) { # \dontrun{
token_provider <- get_token_provider(
  scope = "https://graph.microsoft.com/.default",
  tenant_id = "my-tenant-id",
  client_id = "my-client-id",
  client_secret = "my-secret"
)
token <- token_provider()
} # }