AzureAuth (version 1.1.0)

normalize_tenant: Normalize GUID and tenant values

Description

These functions are used by get_azure_token to recognise and properly format tenant and app IDs.

Usage

normalize_tenant(tenant)

normalize_guid(x)

is_guid(x)

Arguments

tenant

For normalize_tenant, a string containing an Azure Active Directory tenant. This can be a name ("myaadtenant"), a fully qualified domain name ("myaadtenant.onmicrosoft.com" or "mycompanyname.com"), or a valid GUID.

x

For is_guid, a character string; for normalize_guid, a string containing a validly formatted GUID.

Value

For is_guid, whether the argument is a validly formatted GUID.

For normalize_guid, the GUID in canonical format. If the argument is not recognised as a GUID, it throws an error.

For normalize_tenant, the normalized ID or name of the tenant.

Details

A tenant can be identified either by a GUID, or its name, or a fully-qualified domain name (FQDN). The rules for normalizing a tenant are:

  1. If tenant is recognised as a valid GUID, return its canonically formatted value

  2. Otherwise, if it is a FQDN, return it

  3. Otherwise, if it is not the string "common", append ".onmicrosoft.com" to it

  4. Otherwise, return the value of tenant

See the link below for GUID formats recognised by these functions.

See Also

get_azure_token

Parsing rules for GUIDs in .NET. is_guid and normalize_guid recognise the "N", "D", "B" and "P" formats.

Examples

Run this code
# NOT RUN {
is_guid("72f988bf-86f1-41af-91ab-2d7cd011db47")    # TRUE
is_guid("{72f988bf-86f1-41af-91ab-2d7cd011db47}")  # TRUE
is_guid("72f988bf-86f1-41af-91ab-2d7cd011db47}")   # FALSE (unmatched brace)
is_guid("microsoft")                               # FALSE

# all of these return the same value
normalize_guid("72f988bf-86f1-41af-91ab-2d7cd011db47")
normalize_guid("{72f988bf-86f1-41af-91ab-2d7cd011db47}")
normalize_guid("(72f988bf-86f1-41af-91ab-2d7cd011db47)")
normalize_guid("72f988bf86f141af91ab2d7cd011db47")

normalize_tenant("microsoft")     # returns 'microsoft.onmicrosoft.com'
normalize_tenant("microsoft.com") # returns 'microsoft.com'
normalize_tenant("72f988bf-86f1-41af-91ab-2d7cd011db47") # returns the GUID

# }

Run the code above in your browser using DataLab