Last active
April 5, 2018 13:09
-
-
Save marinsagovac/97b6afd6e17c571855a30eefe1b7a956 to your computer and use it in GitHub Desktop.
Vagrant + Kong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"enabled_in_cluster": [# Vagrant | |
# Make sure that you are not listening ports that uses Vagrants: | |
lsof -i tcp:8000 | |
Make sure that is some other port used is closed. | |
If uses then Vagrant boxes will not start | |
# Possible issues on run/fix | |
curl http://localhost:8001 | |
No returns. | |
After Kong started, run | |
vagrant ssh | |
Check ifconfig ip address: | |
10.0.2.15 | |
Starting Kong: | |
kong start --run-migrations | |
You got result: | |
curl http://localhost:8001 | |
# Installation | |
sudo apt-get install virtualbox | |
sudo apt-get install vagrant | |
# Install Kong | |
https://github.com/Kong/kong-vagrant | |
git clone https://github.com/Kong/kong-vagrant | |
cd kong-vagrant | |
vagrant up | |
vagrant ssh | |
kong start --run-migrations | |
curl http://localhost:8001 | |
# Installing boxes | |
vagrant box add hashicorp/precise64 | |
# SSH login | |
vagrant ssh | |
# To install plugins, check on server: | |
curl http://localhost:8001 | |
# you see lists available list of plugins: | |
{ | |
"version": "0.12.1", | |
"plugins": { | |
"enabled_in_cluster": [], | |
"available_on_server": { | |
"response-transformer": true, | |
"correlation-id": true, | |
"statsd": true, | |
"jwt": true, | |
# Installation plugin | |
# Enable plugin from list | |
curl -X POST http://localhost:8001/plugins --data "name=jwt" | |
Check it: | |
curl http://localhost:8001 | |
# you see activated plugin: | |
{ | |
"version": "0.12.1", | |
"plugins": { | |
"enabled_in_cluster": [ | |
"jwt" | |
], | |
# Get consumers | |
curl 0.0.0.0:8001/consumers/ | |
# Create a new consumer | |
curl -X POST http://localhost:8001/consumers --data "username=marin" | |
# Create a consumer with custom field custom_id: | |
curl -X POST http://localhost:8001/consumers --data "username=marin2" --data "custom_id=123" | |
# Create JWT token | |
curl -H "Content-Type: application/json" -X POST -d '{}' http://localhost:8001/consumers/marin/jwt | |
Will return: | |
{"created_at":1519724046000,"id":"4d807403-e085-4915-aab0-71f9a7aeeda0","algorithm":"HS256","key":"29R1RWhoDDw7V6m5WTgV8jMCb8Cg7XS2","secret":"EL0PkoFBBJmIPQ4q6mSTGtHAi5Ea0YZq","consumer_id":"1e5dc636-22f6-4b9c-aa61-add553d27722"} | |
# Check if available token: | |
marin@marin:/opt$ curl -X GET http://localhost:8001/consumers/marin/jwt | |
{"total":1,"data":[{"created_at":1519724046000,"id":"4d807403-e085-4915-aab0-71f9a7aeeda0","algorithm":"HS256","key":"29R1RWhoDDw7V6m5WTgV8jMCb8Cg7XS2","secret":"EL0PkoFBBJmIPQ4q6mSTGtHAi5Ea0YZq","consumer_id":"1e5dc636-22f6-4b9c-aa61-add553d27722"}]} | |
marin@marin:/opt$ curl -X GET http://localhost:8001/consumers/marin2/jwt | |
{"total":0,"data":[]} | |
Get all tokens: | |
curl -X GET http://localhost:8001/jwts | |
# Checkout associated by key token: | |
marin@marin:/opt$ curl -X GET http://localhost:8001/jwts/29R1RWhoDDw7V6m5WTgV8jMCb8Cg7XS2/consumer | |
{"created_at":1519723889000,"username":"marin","id":"1e5dc636-22f6-4b9c-aa61-add553d27722"} | |
## Additional Info ## | |
Check kong: | |
curl -i -X GET localhost:8001 | |
Check all consumers token: | |
curl 0.0.0.0:8001/consumers/ | |
Check email: | |
curl -X POST http://127.0.0.1:8001/consumers --data "username=marin" | |
Check by user: | |
curl -H "Content-Type: application/json" -X POST -d '{}' http://localhost:8001/consumers/marin/jwt | |
Check by token: | |
curl -X GET http://localhost:8001/jwts/oXIHL3fsxS0hXHYtFDuMMoeCIr31bLn9/consumer | |
Check token: | |
curl -X GET --url http://localhost:8000/get -H 'Host: localhost' -H "Authorization:Bearer oXIHL3fsxS0hXHYtFDuMMoeCIr31bLn9" | |
********************* | |
== Lists of all JWTS | |
http://localhost:8001/jwts | |
== Kong JWT | |
Install JWT plugin from Kong. Check: http://localhost:8001/plugins/ | |
== Activate JWT: | |
curl -X POST http://localhost:8001/plugins --data "name=jwt" | |
== Create a key by user: | |
curl -X POST http://localhost:8001/consumers --data "username=marin.sagovac_email.com" | |
== Create a token: | |
Check token | |
curl -X GET http://localhost:8001/consumers/marin.sagovac_email.com/jwt | |
Token not exists now. | |
Create a token | |
curl -H "Content-Type: application/json" -X POST -d '{}' http://localhost:8001/consumers/marin.sagovac_email.com/jwt | |
Token exists. | |
curl -X GET http://localhost:8001/consumers/marin.sagovac_email.com/jwt | |
== Fetch a token | |
curl -X GET http://localhost:8001/consumers/marin.sagovac_email.com/jwt | |
Get a key. | |
== Check token | |
curl -X GET http://localhost:8001/jwts/Ek5GthEs78zw68rmORVApN4GiEk5kKf1/consumer | |
If exists fetch id. (822d17ea-1a7a-4508-aa9e-dfb5c0c5a374) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment