$ docker run -d --name kong \
--link kong-database:kong-database \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong
You can also just create the route, use URL with your API URL
$ curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=local-auth-jwt' \
--data 'url=http://localhost:5000'
$ curl -X POST http://localhost:8001/services/local-auth-jwt/plugins \
--data "name=jwt" \
--data "config.secret_is_base64=false" \
--data "config.run_on_preflight=true"
$ curl -X POST http://localhost:8001/services/local-auth-jwt/routes \
--data "name=auth" \
--data "protocols[]=http" \
--data "paths[]=/jwt-auth"
$ curl -X POST http://localhost:8001/consumers \
--data "username=yourusername.com" \
--data "tags[]=normal_user"
$ curl -X POST http://localhost:8001/consumers/yourusername.com/jwt
{
"tags":null,
"key":"bJEUYhtuCSmqM9LbLPOiUja2f8LRVHQy",
"consumer": {
"id":"f3c82941-a0c1-46bb-b394-301e7ad9d094"
},
"id":"98bdc402-f8d7-4c0d-b0bf-38933d3ca980",
"algorithm":"HS256",
"created_at":1629871731,
"rsa_public_key":null,
"secret":"Dzhj0g9rTkR3Gkk8dJj1iyYskdnsHZ8I"
}
Please dont forget to create your signed key!
Code are just pseduocode, update later
import jwt from 'jsonwebtoken';
const token = jwt.sign({ username: userId }, jwtSecret.secret, {
algorithm: jwtSecret.algorithm,
keyid: jwtSecret.key,
});
$ curl -X GET http://localhost:8001/jwts/{jwt-key}/consumer
{
"tags": ["normal_user"],
"created_at":1629871636,
"custom_id":null,
"username":"[email protected]",
"id":"f3c82941-a0c1-46bb-b394-301e7ad9d094"
}
After that you register your endpoint to Kong, you already do that when you create a service, so you can use it like this POST localhost:8001/service/
with your bearer token included on those request. Kong will inject some headers so you can get it with this.
req.headers['x-consumer-username']