Higher-level AuthKit authentication flow helpers.
Layered on top of WorkOS.UserManagement:
get_authorization_url/2— build an AuthKit authorization URLget_pkce_authorization_url/2— same, with PKCE and state generated automaticallypkce_code_exchange/3— exchange an authorization code with a PKCE code verifierstart_device_authorization/3andpoll_device_code/3— the OAuth 2.0 device authorization flow (RFC 8628)
Summary
Functions
Builds an AuthKit authorization URL. See
WorkOS.UserManagement.get_authorization_url/2 for the supported params.
Builds an AuthKit authorization URL with automatically generated PKCE
parameters, plus a random state unless one is passed in params.
Exchanges an authorization code using a PKCE code verifier (public-client flow).
Polls the authenticate endpoint until the user completes device authorization.
Initiates a device authorization flow, returning the device/user codes and verification URIs.
Types
@type pkce_authorization_url() :: %{ url: String.t(), code_verifier: String.t(), state: String.t() }
Result of get_pkce_authorization_url/2.
Functions
@spec get_authorization_url(WorkOS.Client.t(), map()) :: String.t()
Builds an AuthKit authorization URL. See
WorkOS.UserManagement.get_authorization_url/2 for the supported params.
@spec get_pkce_authorization_url(WorkOS.Client.t(), map()) :: pkce_authorization_url()
Builds an AuthKit authorization URL with automatically generated PKCE
parameters, plus a random state unless one is passed in params.
Store code_verifier securely — it is required for the token exchange.
@spec pkce_code_exchange(WorkOS.Client.t(), map(), keyword()) :: {:ok, WorkOS.AuthenticateResponse.t()} | {:error, WorkOS.Error.error()}
Exchanges an authorization code using a PKCE code verifier (public-client flow).
Parameters
params— map with:codeand:code_verifier
@spec poll_device_code(WorkOS.Client.t(), String.t(), keyword()) :: {:ok, WorkOS.AuthenticateResponse.t()} | {:error, WorkOS.Error.error()}
Polls the authenticate endpoint until the user completes device authorization.
Waits :interval seconds (default 5, as
recommended by the device authorization response) between attempts while the
API reports authorization_pending. Options:
:interval— seconds between polls:max_attempts— give up after this many polls (default:infinity), returning the lastauthorization_pendingerror
@spec start_device_authorization(WorkOS.Client.t(), map(), keyword()) :: {:ok, WorkOS.DeviceAuthorizationResponse.t()} | {:error, WorkOS.Error.error()}
Initiates a device authorization flow, returning the device/user codes and verification URIs.