Skip to content

Instantly share code, notes, and snippets.

@mvanholsteijn
Created December 7, 2017 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanholsteijn/7e94d7124e8438e95054a5f94c02da45 to your computer and use it in GitHub Desktop.
Save mvanholsteijn/7e94d7124e8438e95054a5f94c02da45 to your computer and use it in GitHub Desktop.
Add a Auth0 JWT plugin on an Kong API Gateway API
#!/bin/bash
DOMAIN=${1:-mvanholsteijn.eu.auth0.com}
KONG_API=http://localhost:8001
PUBLIC_KEY=$(curl -sS https://${DOMAIN}/pem | openssl x509 -pubkey -noout)
[[ -z $PUBLIC_KEY ]] && echo "ERROR: could not retrieve public key of $PUBLIC_KEY" && exit 1
# add user
curl -sS -i -X POST $KONG_API/consumers --data username=$DOMAIN
# add public key to consumer
curl -i -X POST $KONG_API/consumers/$DOMAIN/jwt \
-F "algorithm=RS256" \
-F "rsa_public_key=${PUBLIC_KEY}" \
-F "key=https://$DOMAIN/"
# add an sample API
curl -i -X POST $KONG_API/apis \
--data "name=headers" \
--data "hostnames=httpbin.org" \
--data "upstream_url=http://httpbin.org/anything"
# add the JWT plugin on the Sample API
curl -i -X POST $KONG_API/apis/headers/plugins \
--data name=jwt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment