Admins Examples

Invite and register an admin using the Admin API. Can be used for automation.

Prerequisites

Set up the following environment variables:

  1. export USERNAME=<username>
  2. export EMAIL=<email>
  3. export WORKSPACE=<workspace>
  4. export HOST=<admin_api_host>
  5. export TOKEN=Kong-Admin-Token:<super_admin_token>

For example:

  1. export USERNAME=drogon
  2. export EMAIL=test@test.com
  3. export WORKSPACE=default
  4. export HOST=127.0.0.1:8001
  5. 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)

  1. Send a request to the registration URL
  1. curl -i http://localhost:8001/$WORKSPACE/admins/$USERNAME?generate_register_url=true \
  2. -H Kong-Admin-Token:$TOKEN
  1. Copy the response and export as an environment variable, for example:

    1. export REGISTER_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDUwNjc0NjUsImlkIjoiM2IyNzY3MzEtNjIxZC00ZjA3LTk3YTQtZjU1NTg0NmJkZjJjIn0.gujRDi2pX_E7u2zuhYBWD4MoPFKe3axMAq-AUcORg2g
  1. 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

  1. curl -i -X http://localhost:8001/$WORKSPACE/admins/register \
  2. --data token=$REGISTER_TOKEN \
  3. --data username=$USERNAME \
  4. --data email=$EMAIL \
  5. --data password="<new_password>"