Skip to main content
Version: 2.x (Latest)

Functions

Every method below exists on both AuthorizerClient (sync) and AsyncAuthorizerClient (async). On the async client the calls are coroutines — await them. Request objects are dataclasses imported from authorizer; responses are dataclasses too.

from authorizer import (
AuthorizerClient, AsyncAuthorizerClient,
LoginRequest, SignUpRequest, MagicLinkLoginRequest,
VerifyOTPRequest, VerifyEmailRequest, ResendOTPRequest,
ResendVerifyEmailRequest, ForgotPasswordRequest, ResetPasswordRequest,
ValidateJWTTokenRequest, ValidateSessionRequest, SessionQueryRequest,
UpdateProfileRequest, GetTokenRequest, RevokeTokenRequest,
CheckPermissionsRequest, ListPermissionsRequest, PermissionCheckInput, FgaTupleInput,
SkipMfaSetupRequest, LockMfaRequest, OtpMfaSetupRequest,
WebauthnRegistrationOptionsRequest, WebauthnRegistrationVerifyRequest,
WebauthnLoginOptionsRequest, WebauthnLoginVerifyRequest, WebauthnDeleteCredentialRequest,
TokenType,
)

Authentication & user management

MethodSignatureReturns
loginlogin(req: LoginRequest)AuthToken
signupsignup(req: SignUpRequest)AuthToken
magic_link_loginmagic_link_login(req: MagicLinkLoginRequest)GenericResponse
verify_otpverify_otp(req: VerifyOTPRequest)AuthToken
verify_emailverify_email(req: VerifyEmailRequest)AuthToken
resend_otpresend_otp(req: ResendOTPRequest)GenericResponse
resend_verify_emailresend_verify_email(req: ResendVerifyEmailRequest)GenericResponse
forgot_passwordforgot_password(req: ForgotPasswordRequest)ForgotPasswordResponse
reset_passwordreset_password(req: ResetPasswordRequest)GenericResponse
validate_jwt_tokenvalidate_jwt_token(req: ValidateJWTTokenRequest)ValidateJWTTokenResponse
validate_sessionvalidate_session(req: ValidateSessionRequest)ValidateSessionResponse
get_meta_dataget_meta_data()MetaData

Authenticated (pass a bearer token via headers)

MethodSignatureReturns
get_sessionget_session(req=None, headers=None)AuthToken
get_profileget_profile(headers=None)User
update_profileupdate_profile(req: UpdateProfileRequest, headers=None)GenericResponse
logoutlogout(headers=None)GenericResponse
deactivate_accountdeactivate_account(headers=None)GenericResponse

Fine-grained authorization

MethodSignatureReturns
check_permissionscheck_permissions(req: CheckPermissionsRequest, headers=None)CheckPermissionsResponse
list_permissionslist_permissions(req: ListPermissionsRequest, headers=None)ListPermissionsResponse

See the dedicated Fine-Grained Authorization page for usage.

MFA setup & recovery

All take a bearer token via headers (or, if the caller doesn't have one yet, an email/phone_number pair that resolves the in-progress MFA session cookie instead).

MethodSignatureReturns
skip_mfa_setupskip_mfa_setup(req: SkipMfaSetupRequest, headers=None)AuthToken
lock_mfalock_mfa(req: LockMfaRequest, headers=None)GenericResponse
email_otp_mfa_setupemail_otp_mfa_setup(req: OtpMfaSetupRequest=None, headers=None)GenericResponse
sms_otp_mfa_setupsms_otp_mfa_setup(req: OtpMfaSetupRequest=None, headers=None)GenericResponse
totp_mfa_setuptotp_mfa_setup(req: OtpMfaSetupRequest=None, headers=None)AuthToken

lock_mfa has no OTP fallback — it locks the account and requires admin recovery (see admin update_user) afterward.

WebAuthn / passkeys

MethodSignatureReturns
webauthn_registration_optionswebauthn_registration_options(req: WebauthnRegistrationOptionsRequest=None, headers=None)WebauthnRegistrationOptionsResponse
webauthn_registration_verifywebauthn_registration_verify(req: WebauthnRegistrationVerifyRequest, headers=None)AuthToken
webauthn_login_optionswebauthn_login_options(req: WebauthnLoginOptionsRequest=None, headers=None)WebauthnLoginOptionsResponse
webauthn_login_verifywebauthn_login_verify(req: WebauthnLoginVerifyRequest, headers=None)AuthToken
webauthn_delete_credentialwebauthn_delete_credential(req: WebauthnDeleteCredentialRequest, headers=None)GenericResponse
webauthn_credentialswebauthn_credentials(headers=None)list[WebauthnCredentialInfo]

webauthn_registration_options/webauthn_login_options return a JSON-encoded options string to feed straight to the browser's navigator.credentials.create() / .get(); webauthn_registration_verify/webauthn_login_verify take the JSON-encoded credential response back. webauthn_delete_credential permanently deletes the registered passkey. webauthn_credentials lists the authenticated caller's own registered passkeys.

OAuth (REST)

MethodSignatureReturns
get_tokenget_token(req: GetTokenRequest)GetTokenResponse
revoke_tokenrevoke_token(req: RevokeTokenRequest)GenericResponse

get_token posts a form-encoded (application/x-www-form-urlencoded) request to /oauth/token and supports four grants: authorization_code (default, needs code + code_verifier), refresh_token, client_credentials (RFC 6749 §4.4), and RFC 8693 token exchange. The client_credentials and token-exchange grants are machine / agent-to-agent flows — server-side only: never send client_secret, client_assertion, or a subject_token/actor_token to untrusted or browser code.

Machine-to-machine (client_credentials)

Get a token for a service account / machine identity created via the admin create_client method:

from authorizer import (
AuthorizerClient, GetTokenRequest, GRANT_TYPE_CLIENT_CREDENTIALS,
)

machine = AuthorizerClient(client_id="SERVICE_CLIENT_ID", authorizer_url="https://your-instance.authorizer.dev")
token = machine.get_token(
GetTokenRequest(grant_type=GRANT_TYPE_CLIENT_CREDENTIALS, client_secret="SERVICE_CLIENT_SECRET")
)
print(token.access_token, token.scope)

Agent delegation (RFC 8693 token exchange)

An agent acting on behalf of a signed-in user exchanges the user's token plus its own machine token for a delegated token. The original user stays the JWT sub; each hop narrows scope and appends to the nested act claim (re-widening scope is rejected):

from authorizer import (
AuthorizerClient, GetTokenRequest,
GRANT_TYPE_CLIENT_CREDENTIALS, GRANT_TYPE_TOKEN_EXCHANGE, TOKEN_TYPE_ACCESS_TOKEN,
)

agent = AuthorizerClient(client_id="AGENT_CLIENT_ID", authorizer_url="https://your-instance.authorizer.dev")

# 1. the agent authenticates as itself
machine_token = agent.get_token(
GetTokenRequest(grant_type=GRANT_TYPE_CLIENT_CREDENTIALS, client_secret="AGENT_CLIENT_SECRET")
)

# 2. exchange the user's token for one delegated to this agent, scoped down
delegated = agent.get_token(
GetTokenRequest(
grant_type=GRANT_TYPE_TOKEN_EXCHANGE,
client_secret="AGENT_CLIENT_SECRET",
subject_token=user_access_token,
subject_token_type=TOKEN_TYPE_ACCESS_TOKEN,
actor_token=machine_token.access_token,
actor_token_type=TOKEN_TYPE_ACCESS_TOKEN,
scope="crm:read",
resource="https://crm.internal.example",
)
)
print(delegated.access_token) # sub is still the user; act.sub is the agent

Escape hatch — raw GraphQL

For any operation not covered by a typed helper:

data = client.graphql_query(
query="query { meta { version } }",
variables=None,
headers=None,
)

graphql_query(query: str, variables=None, headers=None) -> dict returns the parsed data object.

Examples

Sign up

from authorizer import AuthorizerClient, SignUpRequest

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")

token = client.signup(SignUpRequest(
email="user@example.com",
password="Abc@123",
confirm_password="Abc@123",
given_name="Ada",
family_name="Lovelace",
))
print(token.message, token.access_token)

Log in and read the profile

from authorizer import AuthorizerClient, LoginRequest

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")

token = client.login(LoginRequest(email="user@example.com", password="Abc@123"))
auth = {"Authorization": f"Bearer {token.access_token}"}

user = client.get_profile(headers=auth)
print(user.id, user.email, user.roles)

Validate a JWT

from authorizer import AuthorizerClient, ValidateJWTTokenRequest, TokenType

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")

res = client.validate_jwt_token(ValidateJWTTokenRequest(
token=access_token,
token_type=TokenType.ACCESS_TOKEN,
))
print(res.is_valid, res.claims)
from authorizer import AuthorizerClient, MagicLinkLoginRequest

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")
res = client.magic_link_login(MagicLinkLoginRequest(email="user@example.com"))
print(res.message) # "Please check your inbox!..."

Request types

All request dataclasses serialize via to_dict(). Fields shown | None are optional.

TypeKey fields
LoginRequestpassword*, email, phone_number, roles, scope, state
SignUpRequestpassword*, confirm_password*, email, given_name, family_name, phone_number, roles, scope, redirect_uri, app_data, …
MagicLinkLoginRequestemail*, roles, scope, state, redirect_uri
VerifyOTPRequestotp*, email, phone_number, is_totp, state
VerifyEmailRequesttoken*, state
ResendOTPRequestemail, phone_number, state
ResendVerifyEmailRequestemail*, identifier
ForgotPasswordRequestemail, phone_number, state, redirect_uri
ResetPasswordRequestpassword*, confirm_password*, token, otp, phone_number
ValidateJWTTokenRequesttoken*, token_type* (TokenType), roles
ValidateSessionRequestcookie, roles
SessionQueryRequestroles, scope
UpdateProfileRequestemail, old_password, new_password, confirm_new_password, given_name, family_name, roles, app_data, …
GetTokenRequestcode, grant_type, refresh_token, code_verifier, client_secret, scope, client_assertion, client_assertion_type, subject_token, subject_token_type, actor_token, actor_token_type, resource
RevokeTokenRequestrefresh_token*
CheckPermissionsRequestchecks* (list[PermissionCheckInput]), user
ListPermissionsRequestrelation, object_type, user
PermissionCheckInputrelation*, object*, contextual_tuples (list[FgaTupleInput])
FgaTupleInputuser*, relation*, object*
SkipMfaSetupRequestemail, phone_number, state
LockMfaRequestemail, phone_number
OtpMfaSetupRequestemail, phone_number (shared by email_otp_mfa_setup / sms_otp_mfa_setup / totp_mfa_setup)
WebauthnRegistrationOptionsRequestemail, phone_number
WebauthnRegistrationVerifyRequestcredential*, name, email, phone_number, state
WebauthnLoginOptionsRequestemail
WebauthnLoginVerifyRequestcredential*, state
WebauthnDeleteCredentialRequestid*

* = required

Response types

All response dataclasses are built via from_dict().

TypeKey fields
AuthTokenmessage, access_token, expires_in, id_token, refresh_token, should_show_*_screen, authenticator_*, user
Userid, email, email_verified, given_name, family_name, phone_number, roles, created_at, app_data, …
GenericResponsemessage
ForgotPasswordResponsemessage, should_show_mobile_otp_screen
ValidateJWTTokenResponseis_valid, claims
ValidateSessionResponseis_valid, user
MetaDataversion, client_id, and is_*_enabled feature flags (login providers, MFA, sign-up, etc.)
GetTokenResponseaccess_token, expires_in, id_token, refresh_token, token_type, scope, issued_token_type
CheckPermissionsResponseresults (list[PermissionCheckResult])
PermissionCheckResultrelation, object, allowed
ListPermissionsResponseobjects, permissions (list[Permission]), truncated
Permissionobject, relation
WebauthnRegistrationOptionsResponseoptions (JSON-encoded PublicKeyCredentialCreationOptions)
WebauthnLoginOptionsResponseoptions (JSON-encoded PublicKeyCredentialRequestOptions)
WebauthnCredentialInfoid, name, transports, created_at, updated_at, last_used_at

Enums

EnumValues
TokenTypeACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN
ResponseTypesCODE, TOKEN
OAuthProvidersAPPLE, GITHUB, GOOGLE, FACEBOOK, LINKEDIN, TWITTER, MICROSOFT, TWITCH, ROBLOX, DISCORD

OAuth grant / token-type constants

Plain string constants (not enums) for building GetTokenRequest — pass their values, or the constants themselves, to grant_type, *_token_type, and client_assertion_type:

ConstantValue
GRANT_TYPE_AUTHORIZATION_CODE"authorization_code"
GRANT_TYPE_REFRESH_TOKEN"refresh_token"
GRANT_TYPE_CLIENT_CREDENTIALS"client_credentials"
GRANT_TYPE_TOKEN_EXCHANGE"urn:ietf:params:oauth:grant-type:token-exchange" (RFC 8693)
TOKEN_TYPE_ACCESS_TOKEN"urn:ietf:params:oauth:token-type:access_token"
TOKEN_TYPE_JWT"urn:ietf:params:oauth:token-type:jwt"
CLIENT_ASSERTION_TYPE_JWT_BEARER"urn:ietf:params:oauth:client-assertion-type:jwt-bearer" (RFC 7523)

Error handling

The SDK raises two exception types:

ExceptionWhen
AuthorizerErrorThe API returned an error. Has message, errors, status.
AuthorizerConnectionErrorA network/transport failure (subclass of AuthorizerError).
from authorizer import AuthorizerClient, LoginRequest, AuthorizerError

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")
try:
client.login(LoginRequest(email="user@example.com", password="wrong"))
except AuthorizerError as err:
print(err.status, err.message)