ExAzureCore.Auth (ex_azure_core v0.1.0)

Copy Markdown

Authentication module for Azure services.

Provides credential server management and token acquisition functionality.

Summary

Functions

Returns a child spec for starting the credential server under a supervisor.

Fetches the current token from a credential server.

Fetches the current token from a credential server, raising on error.

Starts a credential server.

Functions

child_spec(opts)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child spec for starting the credential server under a supervisor.

Examples

children = [
  {ExAzureIdentity,
    name: MyApp.AzureToken,
    source: {:client_assertion, config}}
]

fetch(name)

@spec fetch(term()) :: {:ok, map()} | {:error, term()}

Fetches the current token from a credential server.

Returns the cached token if available and still valid, otherwise fetches a new one from the token source.

Parameters

  • name - The name of the credential server

Returns

  • {:ok, token} - A map containing the access token and metadata
  • {:error, reason} - An error tuple with the failure reason

Examples

{:ok, token} = ExAzureCore.Auth.fetch(MyApp.AzureToken)
token.access_token
#=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik..."
token.expires_at
#=> 1234567890

fetch!(name)

@spec fetch!(term()) :: map()

Fetches the current token from a credential server, raising on error.

Parameters

  • name - The name of the credential server

Returns

A map containing the access token and metadata.

Raises

Raises a runtime error if the token cannot be fetched.

Examples

token = ExAzureCore.Auth.fetch!(MyApp.AzureToken)
token.access_token
#=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik..."

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a credential server.

This function is typically called via a child spec in a supervision tree.

Options

See module documentation for available options.

Examples

{:ok, pid} = ExAzureCore.Auth.start_link(
  name: :my_credential,
  source: {:client_assertion, %{
    tenant_id: "...",
    client_id: "...",
    scope: "https://graph.microsoft.com/.default",
    provider: :aws_cognito,
    provider_opts: [identity_id: "..."]
  }}
)