Skip to main content
Please review this guide thoroughly to understand the changes required to migrate from go-auth0 v1 to go-auth0 v2

Overview

The Auth0 Go SDK v2 represents a complete rewrite of the SDK with the following major improvements:

Generated from OpenAPI

v2 is generated from Auth0’s OpenAPI specifications, ensuring consistency and accuracy

Improved Type Safety

Strongly typed request/response structures with proper enums and validation

Better Organization

Management APIs are organized into dedicated subpackages

Enhanced Developer Experience

Better IntelliSense support and clear method signatures

Breaking Changes

Module Name Change

The import path has changed from github.com/auth0/go-auth0 to github.com/auth0/go-auth0/v2.
import (
    "github.com/auth0/go-auth0"
    "github.com/auth0/go-auth0/management"
)

Package Structure Reorganization

v2 organizes management APIs into dedicated subpackages, replacing the monolithic structure of v1.
management/
├── client.go
├── user.go
├── connection.go
├── role.go
└── ... (all in root)

Generated Code and Type Safety

v2 uses generated code with strictly typed structures and enums, replacing the loosely typed approach of v1.
client := &management.Client{
    Name:    auth0.String("My App"),
    AppType: auth0.String("spa"),
    // Many fields are *string
}

Management Client Initialization

The way you initialize and access management clients has changed significantly.
import "github.com/auth0/go-auth0/management"

mgmt, err := management.New(
    domain,
    management.WithClientCredentials(
        context.Background(),
        clientID,
        clientSecret,
    ),
)

// Access managers directly
client, err := mgmt.Client.Create(ctx, clientData)

API Method Signatures

Method signatures have been updated with more specific types and clearer parameter structures.
// Create a client
func (m *ClientManager) Create(
    ctx context.Context,
    c *Client,
    opts ...RequestOption,
) error

// List clients
func (m *ClientManager) List(
    ctx context.Context,
    opts ...RequestOption,
) (*ClientList, error)

Request and Response Types

v2 introduces specific request and response types for each operation.
// Single type for all operations
client := &management.Client{
    Name: auth0.String("My App"),
    // ... other fields
}

err := mgmt.Client.Create(ctx, client)

Migration Steps

Step 1: Update Dependencies

Update your go.mod file:
# Remove old dependency
go mod edit -droprequire github.com/auth0/go-auth0

# Add new dependency
go get github.com/auth0/go-auth0/v2

Step 2: Update Imports

Replace all imports:
import "github.com/auth0/go-auth0/management"

Step 3: Update Client Initialization

mgmt, err := management.New(
    domain,
    management.WithClientCredentials(ctx, clientID, clientSecret),
)

Step 4: Update API Calls

Update your API calls to use the new structure and types:
client := &management.Client{
    Name: auth0.String("My App"),
}
err := mgmt.Client.Create(ctx, client)

Examples

Client Management

package main

import (
    "context"
    "github.com/auth0/go-auth0"
    "github.com/auth0/go-auth0/management"
)

func main() {
    mgmt, err := management.New(
        "your-domain.auth0.com",
        management.WithClientCredentials(
            context.Background(),
            "client-id",
            "client-secret",
        ),
    )
    if err != nil {
        panic(err)
    }

    // Create client
    client := &management.Client{
        Name:    auth0.String("My App"),
        AppType: auth0.String("spa"),
        Callbacks: &[]string{
            "http://localhost:3000/callback",
        },
    }

    err = mgmt.Client.Create(context.Background(), client)
    if err != nil {
        panic(err)
    }

    // List clients
    clients, err := mgmt.Client.List(context.Background())
    if err != nil {
        panic(err)
    }
}

User Management

// Create user
user := &management.User{
    Email:      auth0.String("[email protected]"),
    Connection: auth0.String("Username-Password-Authentication"),
    Password:   auth0.String("password123"),
}

err := mgmt.User.Create(ctx, user)

// List users
users, err := mgmt.User.List(ctx)

Connection Management

// Create connection
connection := &management.Connection{
    Name:     auth0.String("my-database"),
    Strategy: auth0.String("auth0"),
    Options: &management.ConnectionOptions{
        BruteForceProtection: auth0.Bool(true),
    },
}

err := mgmt.Connection.Create(ctx, connection)

Authentication Package

The authentication package remains largely unchanged between v1 and v2. You can continue using it with minimal modifications:
// Both v1 and v2 support similar authentication patterns
import "github.com/auth0/go-auth0/v2/authentication"

auth, err := authentication.New(
    context.Background(),
    "your-domain.auth0.com",
    authentication.WithClientID("client-id"),
    authentication.WithClientSecret("client-secret"),
)

Additional Notes

All v2 methods require a context.Context as the first parameter
v2 uses a consistent option pattern for configuration
Error types may have changed - review your error handling logic
Take advantage of the improved type safety by using the provided enums and constants

Troubleshooting

Common Issues

1

Import Errors

Make sure to update all import statements to use the new module path github.com/auth0/go-auth0/v2
2

Type Mismatches

Use the new strongly-typed structures instead of generic map types. Replace pointer string helpers with direct values or the new helper functions.
3

Method Not Found

Check the new package structure - methods may have moved to subpackages. For example, mgmt.Client is now mgmt.Clients
4

Initialization Errors

Use the new client initialization pattern with options from the option package

Getting Help

API Reference

Check the API reference documentation

GitHub Examples

Review examples in the repository

GitHub Issues

Open an issue for migration problems
This migration guide covers the major changes needed to upgrade from go-auth0 v1 to go-auth0 v2. While the changes are significant, the improved type safety and organization make the SDK more robust and easier to use.

Build docs developers (and LLMs) love