Connections represent identity providers that users can authenticate with. Use this API to configure database connections, social providers, enterprise connections, and passwordless methods.
List Connections
Retrieves a detailed list of all connections matching the specified criteria.
func (c *Client) List(
ctx context.Context,
request *management.ListConnectionsQueryParameters,
opts ...option.RequestOption,
) (*core.Page[*string, *management.ConnectionForList, *management.ListConnectionsCheckpointPaginatedResponseContent], error)
request
*management.ListConnectionsQueryParameters
Query parameters:
Strategy - Filter by connection strategy
Name - Filter by connection name
Fields - Fields to include or exclude
IncludeFields - Whether to include or exclude fields
Take - Number of results (default: 50)
From - Cursor for checkpoint pagination
Example
import (
"context"
"fmt"
"log"
"github.com/auth0/go-auth0/v2/management"
)
params := &management.ListConnectionsQueryParameters{
Strategy: []string{"auth0", "google-oauth2"},
Take: management.Int(50),
}
page, err := client.Management.Connections.List(context.TODO(), params)
if err != nil {
log.Fatalf("Failed to list connections: %v", err)
}
for _, conn := range page.Results {
fmt.Printf("Connection: %s (Strategy: %s)\n", conn.GetName(), conn.GetStrategy())
}
Get Connection
Retrieves details for a specific connection.
func (c *Client) Get(
ctx context.Context,
id string,
request *management.GetConnectionRequestParameters,
opts ...option.RequestOption,
) (*management.GetConnectionResponseContent, error)
The ID of the connection to retrieve
request
*management.GetConnectionRequestParameters
Query parameters:
Fields - Fields to include or exclude
IncludeFields - Whether to include or exclude fields
connection
*management.GetConnectionResponseContent
Returns the connection with properties:
ID - Connection identifier
Name - Connection name
Strategy - Connection strategy type
DisplayName - Display name
Options - Strategy-specific options
EnabledClients - Array of client IDs that can use this connection
Realms - Associated realms
Metadata - Custom metadata
Example
conn, err := client.Management.Connections.Get(
context.TODO(),
"con_1234567890",
&management.GetConnectionRequestParameters{},
)
if err != nil {
log.Fatalf("Failed to get connection: %v", err)
}
fmt.Printf("Connection: %s\n", conn.GetName())
fmt.Printf("Strategy: %s\n", conn.GetStrategy())
Create Connection
Creates a new connection.
func (c *Client) Create(
ctx context.Context,
request *management.CreateConnectionRequestContent,
opts ...option.RequestOption,
) (*management.CreateConnectionResponseContent, error)
request
*management.CreateConnectionRequestContent
required
The connection configuration:
Name - Connection name (required)
Strategy - Connection strategy (required)
DisplayName - Display name
Options - Strategy-specific options
EnabledClients - Array of client IDs
Realms - Associated realms
Metadata - Custom metadata
Example: Database Connection
options := &management.Auth0ConnectionOptions{
PasswordPolicy: management.String("good"),
RequiresUsername: management.Bool(false),
BruteForceProtection: management.Bool(true),
}
conn := &management.CreateConnectionRequestContent{
Name: "my-database",
Strategy: "auth0",
DisplayName: management.String("My Database"),
Options: options,
EnabledClients: []string{"client-id-1", "client-id-2"},
}
created, err := client.Management.Connections.Create(context.TODO(), conn)
if err != nil {
log.Fatalf("Failed to create connection: %v", err)
}
fmt.Printf("Created connection: %s\n", created.GetID())
Example: Google OAuth2 Connection
options := &management.GoogleOAuth2ConnectionOptions{
ClientID: management.String("google-client-id"),
ClientSecret: management.String("google-client-secret"),
AllowedAudiences: []string{"example.com"},
Scopes: []string{"email", "profile"},
}
conn := &management.CreateConnectionRequestContent{
Name: "google-oauth2",
Strategy: "google-oauth2",
Options: options,
EnabledClients: []string{"client-id-1"},
}
created, err := client.Management.Connections.Create(context.TODO(), conn)
Update Connection
Updates an existing connection’s configuration.
func (c *Client) Update(
ctx context.Context,
id string,
request *management.UpdateConnectionRequestContent,
opts ...option.RequestOption,
) (*management.UpdateConnectionResponseContent, error)
The ID of the connection to update
request
*management.UpdateConnectionRequestContent
required
The fields to update
Example
update := &management.UpdateConnectionRequestContent{
DisplayName: management.String("Updated Display Name"),
EnabledClients: []string{"client-id-1", "client-id-2", "client-id-3"},
}
updated, err := client.Management.Connections.Update(
context.TODO(),
"con_1234567890",
update,
)
if err != nil {
log.Fatalf("Failed to update connection: %v", err)
}
Delete Connection
Deletes a connection. Users can no longer authenticate with this connection once removed.
func (c *Client) Delete(
ctx context.Context,
id string,
opts ...option.RequestOption,
) error
The ID of the connection to delete
Example
err := client.Management.Connections.Delete(
context.TODO(),
"con_1234567890",
)
if err != nil {
log.Fatalf("Failed to delete connection: %v", err)
}
Check Connection Status
Checks the status of an AD/LDAP connection.
func (c *Client) CheckStatus(
ctx context.Context,
id string,
opts ...option.RequestOption,
) error
ID of the connection to check
Example
err := client.Management.Connections.CheckStatus(
context.TODO(),
"con_1234567890",
)
if err != nil {
log.Printf("Connection is offline: %v", err)
} else {
fmt.Println("Connection is online")
}
Connection Strategies
Common connection strategies:
auth0 - Database connections
google-oauth2 - Google
facebook - Facebook
apple - Apple
github - GitHub
windowslive - Microsoft Account
linkedin - LinkedIn
samlp - SAML
waad - Azure AD
adfs - ADFS
oidc - Generic OIDC
oauth2 - Generic OAuth2
ad - Active Directory/LDAP
sms - Passwordless SMS
email - Passwordless Email
Complete Example
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/auth0/go-auth0/v2/management"
)
func main() {
client, err := management.New(
context.TODO(),
os.Getenv("AUTH0_DOMAIN"),
management.WithClientCredentials(
os.Getenv("AUTH0_CLIENT_ID"),
os.Getenv("AUTH0_CLIENT_SECRET"),
),
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Create a database connection
options := &management.Auth0ConnectionOptions{
PasswordPolicy: management.String("excellent"),
RequiresUsername: management.Bool(false),
BruteForceProtection: management.Bool(true),
}
conn := &management.CreateConnectionRequestContent{
Name: "my-user-database",
Strategy: "auth0",
DisplayName: management.String("User Database"),
Options: options,
EnabledClients: []string{os.Getenv("AUTH0_CLIENT_ID")},
}
created, err := client.Management.Connections.Create(context.TODO(), conn)
if err != nil {
log.Fatalf("Failed to create connection: %v", err)
}
fmt.Printf("Created connection: %s\n", created.GetID())
// List all connections
page, err := client.Management.Connections.List(
context.TODO(),
&management.ListConnectionsQueryParameters{},
)
if err != nil {
log.Fatalf("Failed to list connections: %v", err)
}
fmt.Println("\nAll connections:")
for _, c := range page.Results {
fmt.Printf("- %s (%s)\n", c.GetName(), c.GetStrategy())
}
}