Sigra.OAuth.Strategies.Github (Sigra v0.2.3)

Copy Markdown View Source

Wraps Assent.Strategy.Github for Sigra OAuth integration.

GitHub uses standard OAuth2. Default scopes: user:email. GitHub returns id as an integer, so normalize_user/1 converts it to a string for consistent UID handling.

Summary

Functions

Generates the authorization URL for GitHub OAuth.

Handles the OAuth callback from GitHub.

Returns the default OAuth scopes for GitHub.

Verifies that the Assent library is available.

Normalizes a GitHub user info map to a consistent shape.

Functions

authorize_url(provider_config)

(since 0.1.0)
@spec authorize_url(keyword()) :: {:ok, map()} | {:error, term()}

Generates the authorization URL for GitHub OAuth.

Delegates to Assent.Strategy.Github's authorize_url function with merged config.

callback(provider_config, params, session_params)

(since 0.1.0)
@spec callback(keyword(), map(), map()) :: {:ok, map(), map()} | {:error, term()}

Handles the OAuth callback from GitHub.

Delegates to Assent.Strategy.Github's callback function and normalizes the user info.

default_scopes()

(since 0.1.0)
@spec default_scopes() :: [String.t()]

Returns the default OAuth scopes for GitHub.

ensure_assent!()

(since 0.1.0)
@spec ensure_assent!() :: :ok

Verifies that the Assent library is available.

Raises a descriptive error if Assent is not loaded (D-14). Returns :ok if available.

normalize_user(user)

(since 0.1.0)
@spec normalize_user(map()) :: map()

Normalizes a GitHub user info map to a consistent shape.

Falls back to to_string(user["id"]) when "sub" is nil, since GitHub returns numeric IDs. Maps "avatar_url" to "picture" for consistency.