Skip to content

A Go library that wraps the Auth0 management API.

License

Notifications You must be signed in to change notification settings

never00rei/go-auth0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-auth0

A Go CLI tool that wraps the Auth0 management API.

Getting Started

Pre-requisites

  1. Working Go installation, preferably 1.21+.
  2. Auth0 tenant.

Working From Source

To get started you can clone the repo: git clone https://github.com/never00rei/go-auth0.git. From there, run the test command go test ./... to ensure tests are running.

Once the tests have completed you can run go run main.go as the main entrypoint.

Setting up Auth0

The Go-Auth0 CLI tool requires a client application attached to the Auth0 Management API for the tenant you're wishing to manage.

Auth0 create a "Management API" when the tenant is created, to gain access to those endpoints we need to create a "machine to machine" application and attach it to the pre-existing management API.

Setting Up A "Machine To Machine" Client

  1. In Auth0, on the left hand menu click "Applications" - from there click the sub-menu "Applications". This will present a list of current applications.
  2. In the top right of the new pane, click "Create Application".
  3. In the new modal window, give your application a name that makes sense and then select "Machine to Machine Applications".
  4. In the "Authorize Machine to Machine Application" select the "Auth0 Management API". This will take you to a scope selection screen.
  5. Select the scopes and actions you wish this tool to be able to perform, and then click "Authorize".
  6. In the new pane, you'll need to grab the "Client ID", "Client Secret" and the API domain:
    • The "Client ID" is next to the title of the application.
    • The "Client Secret" can be found under the "Credentails" tab.
    • The api domain an be found under the "API" tab, all we need is the domain not the entire URL: <TENANT_NAME>.<REGION>.auth0.com

Configuring Go-Auth0 CLI Tool

The Go-Auth0 CLI tool stores the Client ID and Secret, along with the API domain, in an INI file style configuration under ~/.auth0/credentials.

To create this file you can use Go-Auth0: go run main.go configure, the tool will ask a series of questions and then save the file under ~/.auth0/credentials as a new configuration.

Note: Recommendation for tenant names, try not to use spaces. If a space is required, use hyphens or underscores.

You can also use the same command to update an existing configuration by using the same tenant name from your configuration.

Using The Go-Auth0 CLI Tool

Once you have a configuration setup, you'll need to generate a token. This can be by using the login command, passing in the tenant name as a parameter to the login command like so: go run main.go login --tenant [TENANT_NAME]

The login command creates a subshell, attaching the token generated by Auth0 to the shell environment. Once you quit the subshell, that token no longer exists.

Once in the subshell, you can use any of the commands like so go run main.go get-users.

About

A Go library that wraps the Auth0 management API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages