Code Monkey home page Code Monkey logo

auth0-go's Introduction

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.

auth0-go's People

Contributors

brianstarke avatar kerryalsace avatar

Forkers

mauipipe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.