auth0

package module
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 2 Imported by: 2

README

Auth0 Go SDK

GoDoc License Release Tests Codecov


Go client library for the Auth0 platform.

Note: This SDK was previously maintained under go-auth0/auth0.


Table of Contents


Installation

go get github.com/auth0/go-auth0

[table of contents]

Documentation

Reference documentation can be found at pkg.go.dev. For more information about Auth0 please visit the Auth0 Docs page and the Auth0 Management API Docs.

[table of contents]

Usage

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

Initialize a new client using a domain, client ID and secret.

m, err := management.New(domain, management.WithClientCredentials(id, secret))
if err != nil {
	// handle err
}

With the management client we can now interact with the Auth0 Management API.

c := &management.Client{
	Name:        auth0.String("Client Name"),
	Description: auth0.String("Long description of client"),
}

err = m.Client.Create(c)
if err != nil {
	// handle err
}

fmt.Printf("Created client %s\n", c.ClientID)

The following Auth0 resources are supported:

[table of contents]

Testing

To run the tests use the make test command. This will make use of pre-recorded http interactions found in the recordings folder. To add new recordings run the tests against an Auth0 tenant individually using the following env var AUTH0_HTTP_RECORDINGS=on.

To run the tests against an Auth0 tenant, use the make test-e2e command. Start by creating an M2M app in the tenant, that has been authorized to call the Management API and has all the required permissions.

Then create a local .env file in the management folder with the following settings:

  • AUTH0_DOMAIN: The Domain of the M2M app
  • AUTH0_CLIENT_ID: The Client ID of the M2M app
  • AUTH0_CLIENT_SECRET: The Client Secret of the M2M app
  • AUTH0_DEBUG: Set to true to call the Management API in debug mode, which dumps the HTTP requests and responses to the output

[table of contents]

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

[table of contents]

Create a free Auth0 Account

  1. Go to Auth0 and click "Try Auth0 for Free".
  2. Use Google, GitHub or Microsoft Account to login.

[table of contents]

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

[table of contents]

Author

Auth0

[table of contents]

License

This project is licensed under the MIT license. See the LICENSE file for more info.

[table of contents]

Documentation

Overview

Package auth0 provides a client for using the Auth0 Management API.

Usage

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

Initialize a new client using a domain, client ID and secret.

m, err := management.New(domain, management.WithClientCredentials(id, secret))
if err != nil {
    // handle err
}

Or using a static token.

m, err := management.New(domain, management.WithStaticToken(token))
if err != nil {
    // handle err
}

With a management client we can then interact with the Auth0 Management API.

c := &management.Client{
    Name:        auth0.String("Client Name"),
    Description: auth0.String("Long description of client"),
}

err = m.Client.Create(c)
if err != nil {
    // handle err
}

Authentication

The auth0 package handles authentication by exchanging the client id and secret supplied when creating a new management client.

This is handled internally using the https://godoc.org/golang.org/x/oauth2 package.

Rate Limiting

The auth0 package also handles rate limiting by respecting the `X-Ratelimit-*` headers sent by the server.

The amount of time the client waits for the rate limit to be reset is taken from the `X-Ratelimit-Reset` header as the amount of seconds to wait.

Configuration

There are several other options that can be specified during the creation of a new client.

m, err := management.New(domain,
    management.WithClientCredentials(id, secret),
    management.WithContext(context.Background()),
    management.WithDebug(true))

Request Options

As with the global client configuration, fine grained configuration can be done on a request basis.

c, err := m.Connection.List(
    management.Context(ctx),
    management.Page(2),
    management.PerPage(10),
    management.IncludeFields("id", "name", "options")
    management.Parameter("strategy", "auth0"),
)

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.13.1"

Version of this library. This value is generated automatically during the release process; DO NOT EDIT.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolValue

func BoolValue(b *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func Float64

func Float64(f float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Value

func Float64Value(f *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Int

func Int(i int) *int

Int returns a pointer to the int value passed in.

func IntValue

func IntValue(i *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func String

func String(s string) *string

String returns a pointer to the string value passed in.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func Stringf

func Stringf(s string, v ...interface{}) *string

Stringf returns a pointer to the string value passed in formatted using fmt.Sprintf.

func Time

func Time(t time.Time) *time.Time

Time returns a pointer to the time value passed in.

func TimeValue

func TimeValue(t *time.Time) time.Time

TimeValue returns the value of the time pointer passed in or the zero value of time if the pointer is nil.

Types

This section is empty.

Directories

Path Synopsis
internal
tag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL