Skip to main content

Prerequisites

Before installing the Auth0 Go SDK, ensure your environment meets these requirements:
1

Go version

Install Go 1.24 or newer. The SDK follows the same support policy as Go, supporting the last two major releases.Verify your Go installation:
go version
2

Auth0 account

Create a free Auth0 account if you don’t have one.
3

Auth0 application

Create an Auth0 application in your Auth0 Dashboard to obtain your credentials:
  • For Authentication API: Create a Regular Web Application, Single Page Application, or Native Application
  • For Management API: Create a Machine to Machine Application and authorize it for the Auth0 Management API

Install the SDK

Install the Auth0 Go SDK using Go modules:
go get github.com/auth0/go-auth0/v2
This command downloads the latest version of the SDK and adds it to your go.mod file.
The SDK uses semantic versioning. The /v2 suffix in the import path indicates you’re using version 2.x of the SDK.

Gather your credentials

You’ll need different credentials depending on which API you’re using.

Authentication API credentials

For the Authentication API, you need:
1

Navigate to your application

Go to the Auth0 Dashboard and select Applications > Applications.
2

Copy credentials

Open your application and copy these values from the Settings tab:
  • Domain (e.g., example.us.auth0.com)
  • Client ID (e.g., EXAMPLE_16L9d34h0qe4NVE6SaHxZEid)
  • Client Secret (e.g., EXAMPLE_XSQGmnt8JdXs23407hrK6XXXXXXX)
Keep your Client Secret secure and never commit it to version control. Use environment variables or a secure configuration management system.

Management API credentials

For the Management API, you need:
1

Create a Machine to Machine application

In the Auth0 Dashboard, go to Applications > Applications and create a new Machine to Machine Application.
2

Authorize for Management API

When prompted, select the Auth0 Management API and grant the necessary permissions (scopes) for your use case.
3

Copy credentials

Copy these values from the application’s Settings tab:
  • Domain (e.g., example.us.auth0.com)
  • Client ID
  • Client Secret

Store credentials securely

Never hardcode credentials in your source code. Use one of these approaches:

Environment variables

Create a .env file in your project root:
AUTH0_DOMAIN=example.us.auth0.com
AUTH0_CLIENT_ID=your_client_id
AUTH0_CLIENT_SECRET=your_client_secret
Add .env to your .gitignore:
echo ".env" >> .gitignore
Load environment variables in your Go application:
package main

import (
    "os"
)

func main() {
    domain := os.Getenv("AUTH0_DOMAIN")
    clientID := os.Getenv("AUTH0_CLIENT_ID")
    clientSecret := os.Getenv("AUTH0_CLIENT_SECRET")
    
    // Use credentials to initialize the SDK
}

Configuration file

Create a configuration file outside your repository:
package config

import (
    "encoding/json"
    "os"
)

type Config struct {
    Auth0Domain       string `json:"auth0_domain"`
    Auth0ClientID     string `json:"auth0_client_id"`
    Auth0ClientSecret string `json:"auth0_client_secret"`
}

func Load(path string) (*Config, error) {
    file, err := os.Open(path)
    if err != nil {
        return nil, err
    }
    defer file.Close()
    
    var config Config
    decoder := json.NewDecoder(file)
    err = decoder.Decode(&config)
    if err != nil {
        return nil, err
    }
    
    return &config, nil
}

Import the SDK

Once installed, import the SDK packages you need:
package main

import (
    "context"
    "log"
    
    "github.com/auth0/go-auth0/v2/authentication"
    "github.com/auth0/go-auth0/v2/authentication/database"
    "github.com/auth0/go-auth0/v2/authentication/oauth"
)

Verify installation

Create a simple program to verify the SDK is installed correctly:
main.go
package main

import (
    "context"
    "fmt"
    "log"
    "os"
    
    "github.com/auth0/go-auth0/v2/management/client"
    "github.com/auth0/go-auth0/v2/management/option"
)

func main() {
    domain := os.Getenv("AUTH0_DOMAIN")
    clientID := os.Getenv("AUTH0_CLIENT_ID")
    clientSecret := os.Getenv("AUTH0_CLIENT_SECRET")
    
    mgmt, err := client.New(
        domain,
        option.WithClientCredentials(
            context.Background(),
            clientID,
            clientSecret,
        ),
    )
    if err != nil {
        log.Fatalf("Failed to create management client: %v", err)
    }
    
    fmt.Println("Auth0 Go SDK initialized successfully!")
    fmt.Printf("Connected to: %s\n", domain)
}
Run the program:
export AUTH0_DOMAIN=your-tenant.auth0.com
export AUTH0_CLIENT_ID=your_client_id
export AUTH0_CLIENT_SECRET=your_client_secret

go run main.go
You should see:
Auth0 Go SDK initialized successfully!
Connected to: your-tenant.auth0.com

Next steps

Quick start

Build your first integration with complete examples

API reference

Explore the complete API documentation

Build docs developers (and LLMs) love