Overview
The Management API client provides comprehensive access to Auth0’s Management API, allowing you to programmatically manage users, applications, connections, and other Auth0 resources. The SDK is primarily auto-generated from Auth0’s OpenAPI specifications.
Initialization
Create a Management API client using the client.New function with your authentication credentials:
import (
" context "
" github.com/auth0/go-auth0/v2/management/client "
" github.com/auth0/go-auth0/v2/management/option "
)
// Standard client credentials with client secret
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithClientCredentials (
context . Background (),
"YOUR_CLIENT_ID" ,
"YOUR_CLIENT_SECRET" ,
),
)
if err != nil {
// handle err
}
Authentication Options
The SDK provides several authentication methods:
Client Credentials with Client Secret
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithClientCredentials (
context . Background (),
"YOUR_CLIENT_ID" ,
"YOUR_CLIENT_SECRET" ,
),
)
Client Credentials with Custom Audience
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithClientCredentialsAndAudience (
context . Background (),
"YOUR_CLIENT_ID" ,
"YOUR_CLIENT_SECRET" ,
"https://custom-api.example.com" ,
),
)
Private Key JWT Authentication
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithClientCredentialsPrivateKeyJwt (
context . Background (),
"YOUR_CLIENT_ID" ,
privateKeyPEM , // PEM-encoded private key
"RS256" ,
),
)
Static Access Token
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithToken ( "YOUR_ACCESS_TOKEN" ),
)
Custom Token Source
For advanced token management scenarios:
import " golang.org/x/oauth2 "
mgmt , err := client . New (
"your-tenant.auth0.com" ,
option . WithTokenSource (
oauth2 . ReuseTokenSource ( nil , myCustomTokenSource ),
),
)
Authentication options (WithClientCredentials, WithClientCredentialsAndAudience, WithClientCredentialsPrivateKeyJwt, WithClientCredentialsPrivateKeyJwtAndAudience, and WithTokenSource) are mutually exclusive. If multiple are provided, the last one applied takes effect.
Client Structure
The Management client exposes specialized sub-clients for each resource type:
type Management struct {
Actions * client . Client
Branding * brandingclient . Client
ClientGrants * clientgrantsclient . Client
Clients * clientsclient . Client
ConnectionProfiles * connectionprofiles . Client
Connections * connectionsclient . Client
CustomDomains * customdomains . Client
DeviceCredentials * devicecredentials . Client
EmailTemplates * emailtemplates . Client
EventStreams * eventstreamsclient . Client
Flows * flowsclient . Client
Forms * forms . Client
UserGrants * usergrants . Client
Groups * groupsclient . Client
Hooks * hooksclient . Client
Jobs * jobsclient . Client
LogStreams * logstreams . Client
Logs * logs . Client
NetworkACLs * networkacls . Client
Organizations * organizationsclient . Client
Prompts * promptsclient . Client
RefreshTokens * refreshtokens . Client
ResourceServers * resourceservers . Client
Roles * rolesclient . Client
Rules * rules . Client
Sessions * sessions . Client
Stats * stats . Client
Tickets * tickets . Client
Users * usersclient . Client
// ... and more
}
Common Operations
Managing Clients
// Create a new client
createRequest := & management . CreateClientRequestContent {
Name : "My Application" ,
AppType : & management . ClientAppTypeEnumSpa ,
Callbacks : [] string { "https://myapp.com/callback" },
OidcConformant : management . Bool ( true ),
}
client , err := mgmt . Clients . Create ( ctx , createRequest )
// List clients
listRequest := & management . ListClientsRequestParameters {
AppType : management . String ( "spa" ),
Page : management . Int ( 0 ),
PerPage : management . Int ( 25 ),
}
clients , err := mgmt . Clients . List ( ctx , listRequest )
// Update a client
updateRequest := & management . UpdateClientRequestContent {
Description : management . String ( "Updated description" ),
}
updatedClient , err := mgmt . Clients . Update ( ctx , clientID , updateRequest )
Managing Users
// Create a user
createUserRequest := & management . CreateUserRequestContent {
Email : "[email protected] " ,
Connection : "Username-Password-Authentication" ,
Password : management . String ( "SecurePass123!" ),
UserMetadata : map [ string ] interface {}{
"preference" : "email" ,
},
}
user , err := mgmt . Users . Create ( ctx , createUserRequest )
// Search users
searchRequest := & management . ListUsersRequestParameters {
Search : management . String ( "email: \" *@example.com \" " ),
Sort : management . String ( "created_at:1" ),
PerPage : management . Int ( 50 ),
}
users , err := mgmt . Users . List ( ctx , searchRequest )
Request Options
You can customize individual requests with options:
import " net/http "
// Add custom headers
clients , err := mgmt . Clients . List (
ctx ,
& management . ListClientsRequestParameters {},
option . WithHTTPHeader ( http . Header {
"X-Custom-Header" : [] string { "custom-value" },
}),
)
// Configure retry attempts
users , err := mgmt . Users . List (
ctx ,
& management . ListUsersRequestParameters {},
option . WithMaxAttempts ( 3 ),
)
// Add extra body properties
response , err := mgmt . Clients . Create (
ctx ,
createRequest ,
option . WithBodyProperties ( map [ string ] interface {}{
"custom_field" : "custom_value" ,
}),
)
Safe Getters Pattern
The SDK provides safe getter methods to avoid nil pointer panics:
// Safe: returns empty string if client.LogoURI is nil
logoURI := client . GetLogoURI ()
// Unsafe: could panic if client.LogoURI is nil
// logoURI := *client.LogoURI
Always use the provided getter methods (e.g., GetName(), GetClientID()) when accessing pointer fields to avoid nil pointer panics.
The Management API supports pagination for list operations. See the Pagination page for detailed information.
Error Handling
The Management API returns typed errors for different HTTP status codes. See the Error Handling page for detailed information.
Next Steps
Pagination Learn about paginating through results
Error Handling Learn how to handle Management API errors