Skip to content

fromz/auth0-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

auth0-go

GoDoc

Helper library for Auth0 Management API

Basics

All requests to the Management API need to use a token, you can get one using the GetToken method.

token, err := auth0.GetToken("client_id", "client_secret", "https://mock.auth0.com/api/v2/", "mock.auth0.com")

fmt.Println(token.AccessToken)
// outputs eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlFqUTVORG[...]

OR

You can create a Client which will keep the token fresh and automatically correctly add in the authorization header to requests.

For example, to call the Create Users endpoint...

c, _ := auth0.NewClient("client_id", "client_secret", "https://mock.auth0.com/api/v2/", "mock.auth0.com")

var res interface{}

c.POST("users", struct {
    Connection    string
    Email         string
    PhoneNumber   string `json:"phone_number"`
    EmailVerified bool   `json:"email_verified"`
    VerifyEmail   bool   `json:"verify_email"`
    PhoneVerified bool   `json:"phone_verified"`
}{
    Connection:    "email",
    Email:         "[email protected]",
    PhoneNumber:   "+121255512121",
    EmailVerified: true,
    VerifyEmail:   false,
    PhoneVerified: true,
}, &res)

fmt.Println(res["user_id"])
// outputs email|59f8db607cd312629715dbb2

The POST and GET methods are such that you can still use this lib for methods we haven't wired up.

For methods that have been wired up, it's easier -

c, err := auth0.NewClient(
    "client id",
    "client secret",
    "https://mock.auth0.com/api/v2/", 
    "mock.auth0.com")

u, err := c.UserCreate(&auth0.UserCreateParams{
    Email:         "[email protected]",
    Connection:    "email",
    UserMetadata:  map[string]string{"favourite_spelling_of_favourite": "favorite"},
    EmailVerified: true,
    PhoneVerified: true,
    VerifyEmail:   false,
})

fmt.Printf("ID: %s", u.UserID)
// output: UserID:"email|59f8dac47cd312629715db8e"

Getting dependencies (if you need to)

auth0-go uses the excellent dep tool and the vendor directory is not included in this repository.

Install the dependencies using dep, e.g. dep ensure.

About

Helper library for Auth0 API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages