A Go CLI tool that wraps the Auth0 management API.
- Working Go installation, preferably 1.21+.
- Auth0 tenant.
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.
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.
- In Auth0, on the left hand menu click "Applications" - from there click the sub-menu "Applications". This will present a list of current applications.
- In the top right of the new pane, click "Create Application".
- In the new modal window, give your application a name that makes sense and then select "Machine to Machine Applications".
- In the "Authorize Machine to Machine Application" select the "Auth0 Management API". This will take you to a scope selection screen.
- Select the scopes and actions you wish this tool to be able to perform, and then click "Authorize".
- 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
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.
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
.