Admins Examples
Invite and register an admin using the Admin API. Can be used for automation.
Prerequisites
Set up the following environment variables:
export USERNAME=<username>
export EMAIL=<email>
export WORKSPACE=<workspace>
export HOST=<admin_api_host>
export TOKEN=Kong-Admin-Token:<super_admin_token>
For example:
export USERNAME=drogon
export EMAIL=test@test.com
export WORKSPACE=default
export HOST=127.0.0.1:8001
export ADMIN_TOKEN=Kong-Admin-Token:hunter2
You may benefit from HTTPie and jq.
Invite an admin
Extract and store the token from the registration URL, either by manually creating an environment variable or by echoing and piping with jq
:
Manual method example
Programmatic method (requires jq)
Send a request to the registration URL
curl -i -X hhttp://localhost:8001/$WORKSPACE/admins/$USERNAME?generate_register_url=true \
-H Kong-Admin-Token:$TOKEN
Copy the response and export as an environment variable, for example:
export REGISTER_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDUwNjc0NjUsImlkIjoiM2IyNzY3MzEtNjIxZC00ZjA3LTk3YTQtZjU1NTg0NmJkZjJjIn0.gujRDi2pX_E7u2zuhYBWD4MoPFKe3axMAq-AUcORg2g
REGISTER_TOKEN=$(curl -i -X http://localhost:8001/$WORKSPACE/admins/$USERNAME?generate_register_url=true -H Kong-Admin-Token:$TOKEN | jq .token -r)
Register the admin
curl -i -X http://localhost:8001/$WORKSPACE/admins/register \
--data token=$REGISTER_TOKEN \
--data username=$USERNAME \
--data email=$EMAIL \
--data password="<new_password>"