-
Notifications
You must be signed in to change notification settings - Fork 11
Configure the key auth plugin for a Service with Kong
$ curl -i -X POST --url http://localhost:8001/services/find-service/plugins/ --data 'name=key-auth'
HTTP/1.1 201 Created Date: Tue, 31 Jul 2018 20:02:56 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/0.14.0 Content-Length: 276
{"created_at":1533067377000,"config":{"key_in_body":false,"run_on_preflight":true,"anonymous":"","hide_credentials":false,"key_names":["apikey"]},"id":"13e71371-013a-4d9f-af96-17bd3a55537b","enabled":true,"service_id":"965c3b89-cba6-4de4-b8af-dc81f8a9c05d","name":"key-auth"}
$ curl -i -X GET --url http://localhost:8000/ --header 'Host: find-service.com'
HTTP/1.1 401 Unauthorized Date: Tue, 31 Jul 2018 20:03:46 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive WWW-Authenticate: Key realm="kong" Server: kong/0.14.0 Content-Length: 41
{"message":"No API key found in request"}
As you can see, now the call to the API fails when no apikey was given.
$ curl -i -X POST --url http://localhost:8001/consumers/ --data "username=Jason"
HTTP/1.1 201 Created Date: Tue, 31 Jul 2018 20:04:51 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/0.14.0 Content-Length: 106
{"custom_id":null,"created_at":1533067491,"username":"Jason","id":"2e4f255f-8430-4acd-af3c-34657ca6de28"}
$ curl -i -X POST --url http://localhost:8001/consumers/Jason/key-auth/ --data 'key=ThisIsMyNEWWWKeyeee'
HTTP/1.1 201 Created Date: Tue, 31 Jul 2018 20:05:59 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/0.14.0 Content-Length: 154
{"id":"37297873-3ff4-4ea3-89b6-8853845c366a","created_at":1533067560000,"key":"ThisIsMyNEWWWKeyeee","consumer_id":"2e4f255f-8430-4acd-af3c-34657ca6de28"}
$ curl -i -X GET --url http://localhost:8000 --header "Host: find-service.com" --header "apikey: ThisIsMyNEWWWKeyeee"
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Access-Control-Allow-Origin: * Bindaas-version: 3.0.6 Date: Tue, 31 Jul 2018 20:11:25 GMT metadata: {} responseTime: 0 tags: [] Vendor: CCI Emory University Server: Jetty(8.1.7.v20120910) X-Kong-Upstream-Latency: 5 X-Kong-Proxy-Latency: 35 Via: kong/0.14.0
[{ "item" : "bulk" , "qty" : 1100.0},{ "item" : "bulk" , "qty" : 1100.0},{ "item" : "bulk" , "qty" : 1100.0 , "nu" : 1.0}]