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

Functions

The AuthorizerClient provides methods to interact with the Authorizer API. Every method takes a request struct as a parameter and returns a response struct or an error.

import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

// Example: Login
res, err := client.Login(&authorizer.LoginRequest{
Email: stringPtr("user@example.com"),
Password: "Abc@123",
})
if err != nil {
panic(err)
}

Authentication & user management

Public methods (no authentication required)

MethodSignatureReturns
LoginLogin(req *LoginRequest) (*AuthTokenResponse, error)*AuthTokenResponse
SignUpSignUp(req *SignUpRequest) (*AuthTokenResponse, error)*AuthTokenResponse
MagicLinkLoginMagicLinkLogin(req *MagicLinkLoginRequest) (*Response, error)*Response
VerifyOTPVerifyOTP(req *VerifyOTPRequest) (*AuthTokenResponse, error)*AuthTokenResponse
VerifyEmailVerifyEmail(req *VerifyEmailRequest) (*AuthTokenResponse, error)*AuthTokenResponse
ResendOTPResendOTP(req *ResendOTPRequest) (*Response, error)*Response
ResendVerifyEmailResendVerifyEmail(req *ResendVerifyEmailRequest) (*Response, error)*Response
ForgotPasswordForgotPassword(req *ForgotPasswordRequest) (*ForgotPasswordResponse, error)*ForgotPasswordResponse
ResetPasswordResetPassword(req *ResetPasswordRequest) (*Response, error)*Response
ValidateJWTTokenValidateJWTToken(req *ValidateJWTTokenRequest) (*ValidateJWTTokenResponse, error)*ValidateJWTTokenResponse
ValidateSessionValidateSession(req *ValidateSessionRequest) (*ValidateSessionResponse, error)*ValidateSessionResponse
GetMetaDataGetMetaData() (*MetaData, error)*MetaData

Authenticated (pass headers map with bearer token)

MethodSignatureReturns
GetSessionGetSession(headers map[string]string) (*AuthTokenResponse, error)*AuthTokenResponse
GetProfileGetProfile(headers map[string]string) (*User, error)*User
UpdateProfileUpdateProfile(req *UpdateProfileRequest, headers map[string]string) (*Response, error)*Response
LogoutLogout(headers map[string]string) (*Response, error)*Response
DeactivateAccountDeactivateAccount(headers map[string]string) (*Response, error)*Response

Fine-grained authorization

MethodSignatureReturns
CheckPermissionsCheckPermissions(req *CheckPermissionsRequest, headers map[string]string) (*CheckPermissionsResponse, error)*CheckPermissionsResponse
ListPermissionsListPermissions(req *ListPermissionsRequest, headers map[string]string) (*ListPermissionsResponse, error)*ListPermissionsResponse

See the dedicated Fine-Grained Authorization documentation for details.

MFA setup & recovery

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

MethodSignatureReturns
SkipMfaSetupSkipMfaSetup(req *SkipMfaSetupRequest, headers map[string]string) (*AuthTokenResponse, error)*AuthTokenResponse
LockMfaLockMfa(req *LockMfaRequest, headers map[string]string) (*Response, error)*Response
EmailOtpMfaSetupEmailOtpMfaSetup(req *EmailOtpMfaSetupRequest, headers map[string]string) (*Response, error)*Response
SmsOtpMfaSetupSmsOtpMfaSetup(req *SmsOtpMfaSetupRequest, headers map[string]string) (*Response, error)*Response
TotpMfaSetupTotpMfaSetup(req *TotpMfaSetupRequest, headers map[string]string) (*AuthTokenResponse, error)*AuthTokenResponse

LockMfa has no OTP fallback — it locks the account and requires admin recovery afterward.

WebAuthn / passkeys

MethodSignatureReturns
WebauthnRegistrationOptionsWebauthnRegistrationOptions(req *WebauthnRegistrationOptionsRequest, headers map[string]string) (*WebauthnRegistrationOptionsResponse, error)*WebauthnRegistrationOptionsResponse
WebauthnRegistrationVerifyWebauthnRegistrationVerify(req *WebauthnRegistrationVerifyRequest, headers map[string]string) (*AuthTokenResponse, error)*AuthTokenResponse
WebauthnLoginOptionsWebauthnLoginOptions(email *string) (*WebauthnLoginOptionsResponse, error)*WebauthnLoginOptionsResponse
WebauthnLoginVerifyWebauthnLoginVerify(req *WebauthnLoginVerifyRequest) (*AuthTokenResponse, error)*AuthTokenResponse
WebauthnDeleteCredentialWebauthnDeleteCredential(id string, headers map[string]string) (*Response, error)*Response
WebauthnCredentialsWebauthnCredentials(headers map[string]string) ([]*WebauthnCredentialInfo, error)[]*WebauthnCredentialInfo

WebauthnRegistrationOptions/WebauthnLoginOptions return JSON-encoded options strings to feed straight to the browser's navigator.credentials.create() / .get(); WebauthnRegistrationVerify/WebauthnLoginVerify take the JSON-encoded credential response back. WebauthnDeleteCredential permanently deletes a registered passkey. WebauthnCredentials lists the authenticated caller's own registered passkeys.

OAuth (REST)

MethodSignatureReturns
GetTokenGetToken(req *GetTokenRequest) (*TokenResponse, error)*TokenResponse
RevokeTokenRevokeToken(req *RevokeTokenRequest) (*Response, error)*Response
RevokeRevoke(req *RevokeRequest) (*Response, error)*Response

GetToken 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 CreateClient method:

import "github.com/authorizerdev/authorizer-go/v2"

machine, err := authorizer.NewAuthorizerClient(
"SERVICE_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

token, err := machine.GetToken(&authorizer.GetTokenRequest{
GrantType: stringPtr(authorizer.GrantTypeClientCredentials),
ClientSecret: stringPtr("SERVICE_CLIENT_SECRET"),
})
if err != nil {
panic(err)
}
fmt.Println(token.AccessToken, 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):

import "github.com/authorizerdev/authorizer-go/v2"

agent, err := authorizer.NewAuthorizerClient(
"AGENT_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

// 1. the agent authenticates as itself
machineToken, err := agent.GetToken(&authorizer.GetTokenRequest{
GrantType: stringPtr(authorizer.GrantTypeClientCredentials),
ClientSecret: stringPtr("AGENT_CLIENT_SECRET"),
})
if err != nil {
panic(err)
}

// 2. exchange the user's token for one delegated to this agent, scoped down
delegated, err := agent.GetToken(&authorizer.GetTokenRequest{
GrantType: stringPtr(authorizer.GrantTypeTokenExchange),
ClientSecret: stringPtr("AGENT_CLIENT_SECRET"),
SubjectToken: &userAccessToken,
SubjectTokenType: stringPtr("urn:ietf:params:oauth:token-type:access_token"),
ActorToken: machineToken.AccessToken,
ActorTokenType: stringPtr("urn:ietf:params:oauth:token-type:access_token"),
Scope: stringPtr("crm:read"),
Resource: stringPtr("https://crm.internal.example"),
})
if err != nil {
panic(err)
}
fmt.Println(delegated.AccessToken) // sub is still the user; act.sub is the agent

Escape hatch — raw GraphQL

For any operation not covered by a typed helper:

res, err := client.ExecuteGraphQL(&authorizer.GraphQLRequest{
Query: `query { meta { version } }`,
Variables: nil,
})
if err != nil {
panic(err)
}

ExecuteGraphQL(req *GraphQLRequest) (map[string]interface{}, error) returns the parsed response data.

Examples

Sign up

import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

token, err := client.SignUp(&authorizer.SignUpRequest{
Email: stringPtr("user@example.com"),
Password: "Abc@123",
ConfirmPassword: "Abc@123",
GivenName: stringPtr("Ada"),
FamilyName: stringPtr("Lovelace"),
})
if err != nil {
panic(err)
}
fmt.Println(token.Message, *token.AccessToken)

Log in and read the profile

import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

token, err := client.Login(&authorizer.LoginRequest{
Email: stringPtr("user@example.com"),
Password: "Abc@123",
})
if err != nil {
panic(err)
}

headers := map[string]string{"Authorization": "Bearer " + *token.AccessToken}

user, err := client.GetProfile(headers)
if err != nil {
panic(err)
}
fmt.Println(user.ID, user.Email, user.Roles)

Validate a JWT

import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

res, err := client.ValidateJWTToken(&authorizer.ValidateJWTTokenRequest{
Token: accessToken,
})
if err != nil {
panic(err)
}
fmt.Println(res.IsValid, res.Claims)
import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

res, err := client.MagicLinkLogin(&authorizer.MagicLinkLoginRequest{
Email: stringPtr("user@example.com"),
})
if err != nil {
panic(err)
}
fmt.Println(res.Message) // "Please check your inbox!..."

Request types

All request structs are serializable to JSON via json.Marshal(). Fields shown as *Type are optional (pointers).

TypeKey fields
LoginRequestPassword, Email, PhoneNumber, Roles, Scope, State
SignUpRequestPassword, ConfirmPassword, Email, GivenName, FamilyName, PhoneNumber, Roles, Scope, RedirectURI, AppData, …
MagicLinkLoginRequestEmail, Roles, Scope, State, RedirectURI
VerifyOTPRequestOTP, Email, PhoneNumber, IsTotp, State
VerifyEmailRequestToken, State
ResendOTPRequestEmail, PhoneNumber, State
ResendVerifyEmailRequestEmail
ForgotPasswordRequestEmail, PhoneNumber, State, RedirectURI
ResetPasswordRequestPassword, ConfirmPassword, Token, OTP, PhoneNumber
ValidateJWTTokenRequestToken, (no explicit type field; server infers from token structure)
ValidateSessionRequestCookie, Roles
UpdateProfileRequestEmail, OldPassword, NewPassword, ConfirmNewPassword, GivenName, FamilyName, Roles, AppData, …
GetTokenRequestCode, GrantType, RefreshToken, CodeVerifier, ClientSecret, Scope, ClientAssertion, ClientAssertionType, SubjectToken, SubjectTokenType, ActorToken, ActorTokenType, Resource
RevokeTokenRequestRefreshToken
RevokeRequestRefreshToken
CheckPermissionsRequestChecks, User
ListPermissionsRequestRelation, ObjectType, User
PermissionCheckInputRelation, Object, ContextualTuples
FgaTupleInputUser, Relation, Object
SkipMfaSetupRequestEmail, PhoneNumber, State
LockMfaRequestEmail, PhoneNumber
EmailOtpMfaSetupRequestEmail, PhoneNumber
SmsOtpMfaSetupRequestEmail, PhoneNumber
TotpMfaSetupRequestEmail, PhoneNumber
WebauthnRegistrationOptionsRequestEmail, PhoneNumber
WebauthnRegistrationVerifyRequestCredential, Name, Email, PhoneNumber, State
WebauthnLoginVerifyRequestCredential, State
WebauthnDeleteCredentialRequestID

Response types

All response structs are deserializable from JSON via json.Unmarshal().

TypeKey fields
AuthTokenResponseMessage, AccessToken, ExpiresIn, IdToken, RefreshToken, ShouldShowEmailOtpScreen, ShouldShowMobileOtpScreen, ShouldShowTotpScreen, ShouldOfferWebauthnMfaSetup, ShouldOfferWebauthnMfaVerify, ShouldOfferEmailOtpMfaSetup, ShouldOfferSmsOtpMfaSetup, AuthenticatorScannerImage, AuthenticatorSecret, AuthenticatorRecoveryCodes, User
UserID, Email, EmailVerified, GivenName, FamilyName, PhoneNumber, Roles, CreatedAt, UpdatedAt, IsMultiFactorAuthEnabled, HasSkippedMfaSetupAt, MfaLockedAt, EnrolledMfaMethods, AppData, …
ResponseMessage
ForgotPasswordResponseMessage, ShouldShowMobileOtpScreen
ValidateJWTTokenResponseIsValid, Claims
ValidateSessionResponseIsValid, User
MetaDataVersion, ClientID, and Is*Enabled feature flags (login providers, MFA, sign-up, etc.)
TokenResponseAccessToken, ExpiresIn, IdToken, RefreshToken, TokenType, Scope, IssuedTokenType
CheckPermissionsResponseResults
PermissionCheckResultRelation, Object, Allowed
ListPermissionsResponseObjects, Permissions, Truncated
PermissionObject, Relation
WebauthnRegistrationOptionsResponseOptions (JSON-encoded PublicKeyCredentialCreationOptions)
WebauthnLoginOptionsResponseOptions (JSON-encoded PublicKeyCredentialRequestOptions)
WebauthnCredentialInfoID, Name, Transports, CreatedAt, UpdatedAt, LastUsedAt

Constants

ConstantValue
GrantTypeAuthorizationCode"authorization_code"
GrantTypeRefreshToken"refresh_token"
GrantTypeClientCredentials"client_credentials"
GrantTypeTokenExchange"urn:ietf:params:oauth:grant-type:token-exchange" (RFC 8693)

Error handling

The SDK returns standard Go errors. Most API errors come back as error messages:

import "github.com/authorizerdev/authorizer-go/v2"

client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
)
if err != nil {
panic(err)
}

token, err := client.Login(&authorizer.LoginRequest{
Email: stringPtr("user@example.com"),
Password: "wrong",
})
if err != nil {
// err will be non-nil
fmt.Println(err)
}

Protocol selection

By default, the client uses GraphQL. You can override this with WithProtocol:

import "github.com/authorizerdev/authorizer-go/v2"

// Use REST endpoints
client, err := authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
authorizer.WithProtocol(authorizer.ProtocolREST),
)

// Use gRPC (requires a separate gRPC endpoint, default 9091)
client, err = authorizer.NewAuthorizerClient(
"YOUR_CLIENT_ID",
"https://your-instance.authorizer.dev",
"https://your-app.example.com",
nil,
authorizer.WithProtocol(authorizer.ProtocolGRPC),
authorizer.WithGRPCEndpoint("your-instance.authorizer.dev:9091"),
)

Utility helpers

The SDK exports pointer constructor helpers for optional fields:

import "github.com/authorizerdev/authorizer-go/v2"

// stringPtr(s) returns a *string pointing to s
// intPtr(i) returns an *int64 pointing to i
// boolPtr(b) returns a *bool pointing to b

email := authorizer.stringPtr("user@example.com")