Skip to main content
The Users resource provides comprehensive user management capabilities including creating, retrieving, updating, and deleting users, as well as managing user metadata, roles, permissions, and more.

Methods

List Users

Retrieve details of users with support for search, filtering, and pagination.
func (c *Client) List(
    ctx context.Context,
    request *management.ListUsersRequestParameters,
    opts ...option.RequestOption,
) (*core.Page[*int, *management.UserResponseSchema, *management.ListUsersOffsetPaginatedResponseContent], error)
request
*management.ListUsersRequestParameters
Query parameters for filtering and pagination
UserResponseSchema
object

Example

ctx := context.Background()

// Search for users by email domain
searchRequest := &management.ListUsersRequestParameters{
    Search:  management.String("email:\"*@example.com\""),
    Sort:    management.String("created_at:1"),
    PerPage: management.Int(25),
}

usersPage, err := mgmt.Users.List(ctx, searchRequest)
if err != nil {
    log.Fatalf("Error searching users: %v", err)
}

fmt.Println("Users with @example.com domain:")
for _, user := range usersPage.Results {
    fmt.Printf("- %s (Created: %s)\n",
        *user.GetEmail(),
        *user.GetCreatedAt(),
    )
}
Auth0 limits the number of users you can return. If you exceed this threshold, use the export job or User Import/Export extension.

Create User

Create a new user for a database or passwordless connection.
func (c *Client) Create(
    ctx context.Context,
    request *management.CreateUserRequestContent,
    opts ...option.RequestOption,
) (*management.CreateUserResponseContent, error)
request
*management.CreateUserRequestContent
required

Example

createUserRequest := &management.CreateUserRequestContent{
    Email:      "[email protected]",
    Connection: "Username-Password-Authentication",
    Password:   management.String("TempPassword123!"),
    UserMetadata: map[string]interface{}{
        "preference": "email",
        "plan":       "premium",
    },
    AppMetadata: map[string]interface{}{
        "role":  "user",
        "scope": "read:profile",
    },
}

userResponse, err := mgmt.Users.Create(ctx, createUserRequest)
if err != nil {
    log.Fatalf("Error creating user: %v", err)
}

fmt.Printf("Created user: %s (ID: %s)\n",
    *userResponse.GetEmail(),
    *userResponse.GetUserID(),
)

Get User

Retrieve user details by ID.
func (c *Client) Get(
    ctx context.Context,
    id string,
    request *management.GetUserRequestParameters,
    opts ...option.RequestOption,
) (*management.GetUserResponseContent, error)
id
string
required
ID of the user to retrieve

Example

user, err := mgmt.Users.Get(ctx, "auth0|123456", 
    &management.GetUserRequestParameters{})
if err != nil {
    log.Fatalf("Error retrieving user: %v", err)
}

fmt.Printf("User: %s\n", user.GetEmail())
fmt.Printf("Email Verified: %t\n", user.GetEmailVerified())

List Users by Email

Find users by email address.
func (c *Client) ListUsersByEmail(
    ctx context.Context,
    request *management.ListUsersByEmailRequestParameters,
    opts ...option.RequestOption,
) ([]*management.UserResponseSchema, error)
request
*management.ListUsersByEmailRequestParameters
required

Example

users, err := mgmt.Users.ListUsersByEmail(ctx, 
    &management.ListUsersByEmailRequestParameters{
        Email: "[email protected]",
    })
if err != nil {
    log.Fatalf("Error finding users: %v", err)
}

for _, user := range users {
    fmt.Printf("Found user: %s (ID: %s)\n", 
        user.GetEmail(), 
        user.GetUserID(),
    )
}
If Auth0 is the identity provider, email addresses are saved in lowercase. Always search using lowercase email addresses.

Update User

Update an existing user’s information.
func (c *Client) Update(
    ctx context.Context,
    id string,
    request *management.UpdateUserRequestContent,
    opts ...option.RequestOption,
) (*management.UpdateUserResponseContent, error)
id
string
required
ID of the user to update
request
*management.UpdateUserRequestContent
required

Example

updateUserRequest := &management.UpdateUserRequestContent{
    UserMetadata: map[string]interface{}{
        "preference":   "sms",
        "plan":         "premium",
        "last_updated": "2024-01-01",
    },
}

updatedUser, err := mgmt.Users.Update(
    ctx,
    "auth0|123456",
    updateUserRequest,
)
if err != nil {
    log.Fatalf("Error updating user: %v", err)
}

fmt.Printf("Updated user metadata: %v\n", updatedUser.UserMetadata)
Metadata fields are merged at the first level only. Nested objects are replaced entirely.

Delete User

Delete a user by ID. This action cannot be undone.
func (c *Client) Delete(
    ctx context.Context,
    id string,
    opts ...option.RequestOption,
) error
id
string
required
ID of the user to delete

Example

err := mgmt.Users.Delete(ctx, "auth0|123456")
if err != nil {
    log.Fatalf("Error deleting user: %v", err)
}

fmt.Println("User deleted successfully")

Regenerate Recovery Code

Generate a new MFA recovery code for a user.
func (c *Client) RegenerateRecoveryCode(
    ctx context.Context,
    id string,
    opts ...option.RequestOption,
) (*management.RegenerateUsersRecoveryCodeResponseContent, error)
id
string
required
ID of the user to regenerate recovery code for

Example

recovery, err := mgmt.Users.RegenerateRecoveryCode(ctx, "auth0|123456")
if err != nil {
    log.Fatalf("Error regenerating recovery code: %v", err)
}

fmt.Printf("New recovery code generated\n")

Revoke Access

Revoke selected resources related to a user (sessions, refresh tokens).
func (c *Client) RevokeAccess(
    ctx context.Context,
    id string,
    request *management.RevokeUserAccessRequestContent,
    opts ...option.RequestOption,
) error
id
string
required
ID of the user

Example

revokeRequest := &management.RevokeUserAccessRequestContent{
    // Specify what to revoke
}

err := mgmt.Users.RevokeAccess(ctx, "auth0|123456", revokeRequest)
if err != nil {
    log.Fatalf("Error revoking access: %v", err)
}

fmt.Println("User access revoked successfully")

Nested Resources

The Users client provides access to many nested resources:
  • mgmt.Users.Roles - Manage user roles
  • mgmt.Users.Permissions - Manage user permissions
  • mgmt.Users.Organizations - Manage user organizations
  • mgmt.Users.Identities - Manage linked identities
  • mgmt.Users.Enrollments - Manage MFA enrollments
  • mgmt.Users.Authenticators - Manage authenticators
  • mgmt.Users.AuthenticationMethods - Manage authentication methods
  • mgmt.Users.Multifactor - Manage MFA settings
  • mgmt.Users.Sessions - Manage user sessions
  • mgmt.Users.Logs - View user logs
  • mgmt.Users.RefreshToken - Manage refresh tokens

Search Query Syntax

Use Lucene query syntax for the Search parameter:
// Search by email domain
Search: management.String("email:\"*@example.com\"")

// Search by name
Search: management.String("name:\"John*\"")

// Complex search
Search: management.String("email_verified:true AND identities.connection:\"google-oauth2\"")

Best Practices

Metadata Organization

Use user_metadata for user-editable data and app_metadata for application-controlled data.

Email Verification

Always verify email addresses before granting full access to your application.

Search Efficiency

Use specific search queries to reduce result sets and improve performance.

Pagination

Always use pagination when listing users to avoid performance issues and API limits.

Build docs developers (and LLMs) love