Assent.Strategy.AzureAD (Assent v0.4.0)

Copy Markdown View Source

Azure Active Directory OpenID Connect strategy.

Configuration

  • :tenant_id - the tenant identifier, optional, defaults to common. May be a directory ID, verified domain, or one of common, organizations, or consumers.

  • :base_url - the Microsoft identity platform issuer, optional, defaults to https://login.microsoftonline.com/{tenant_id}/v2.0

See Assent.Strategy.OIDC for more.

Usage

config = [
  client_id: "REPLACE_WITH_CLIENT_ID",
  client_secret: "REPLACE_WITH_CLIENT_SECRET",
  redirect_uri: "http://localhost:4000/auth/callback"
]

A tenant identifier can be set to limit which users can get access:

config = [
  client_id: "REPLACE_WITH_CLIENT_ID",
  client_secret: "REPLACE_WITH_CLIENT_SECRET",
  tenant_id: "REPLACE_WITH_TENANT_ID",
  redirect_uri: "http://localhost:4000/auth/callback"
]

Setting up Azure AD

Login to Azure, and set up a new application:

  • The callback URL should be added to "Redirect URI" for the application.
  • client_id is the "Application ID".

Summary

Functions

Generates an OpenID Connect authorization URL.

Handles an OpenID Connect callback.

Fetches user data from an ID Token or the UserInfo endpoint.

Returns user claims without provider-specific normalization.

Functions

authorize_url(config)

@spec authorize_url(Keyword.t()) :: Assent.Strategy.OIDC.on_authorize_url()

Generates an OpenID Connect authorization URL.

callback(config, params)

@spec callback(Keyword.t(), map()) :: Assent.Strategy.OIDC.on_callback()

Handles an OpenID Connect callback.

fetch_user(config, token)

@spec fetch_user(Keyword.t(), map()) :: {:ok, map()} | {:error, term()}

Fetches user data from an ID Token or the UserInfo endpoint.

normalize(config, user)

Returns user claims without provider-specific normalization.