get_manual_token: Get a manual Azure token

View source: R/token_manual.R

get_manual_tokenR Documentation

Get a manual Azure token

Description

Create an Azure token object from a pre-existing access token string. This is useful when you have obtained a token externally (e.g., via Azure CLI, Python, or another authentication mechanism) and want to use it with the AzureR ecosystem.

Usage

get_manual_token(token, type = "Bearer", tenant = NULL, resource = NULL)

Arguments

token

A character string containing the access token.

type

The token type, usually "Bearer".

tenant

Optional tenant ID. If NULL, will be extracted from JWT claims if possible.

resource

Optional resource/audience URL or GUID. If NULL, will be extracted from JWT claims if possible.

Details

This function creates an AzureManualToken object that wraps an externally-obtained access token. The token object can then be used with packages like AzureGraph, AzureRMR, and other AzureR family packages.

If the provided token is a JWT (JSON Web Token), the function will attempt to parse it to extract metadata like tenant ID, resource, and expiration time. For opaque tokens or tokens that cannot be parsed, you can provide the tenant and resource parameters manually.

Value

An object of class AzureManualToken, inheriting from AzureToken.

Token sources

Common ways to obtain tokens externally include:

  • Azure CLI: az account get-access-token --resource <resource>

  • Azure PowerShell: Get-AzAccessToken -ResourceUrl <resource>

  • Python (azure-identity): DefaultAzureCredential().get_token(<scope>)

  • MSAL libraries in various languages

Limitations

Manual tokens have the following limitations compared to tokens obtained via get_azure_token:

  • Cannot be automatically refreshed when they expire

  • Are not cached to disk

  • May have incomplete metadata if JWT parsing fails

See Also

AzureManualToken, get_azure_token, decode_jwt

Examples

## Not run: 
# Example: Use a token from Azure CLI
# First, get the token from command line:
# az account get-access-token --resource https://graph.microsoft.com --query accessToken -o tsv

raw_token <- "eyJ0eXAiOiJKV1QiLC..."
token <- get_manual_token(raw_token)

# Check token properties
print(token)
token$validate()

# Use with AzureGraph
library(AzureGraph)
gr <- ms_graph$new(token = token)

# For opaque tokens, provide metadata explicitly
token2 <- get_manual_token(
    token = "opaque_token_string",
    tenant = "your-tenant-id",
    resource = "https://management.azure.com/"
)

## End(Not run)


AzureAuth documentation built on Dec. 20, 2025, 5:07 p.m.