adaniloff / kong-user-bundle
A little package to help you integrate the Kong solution.
Installs: 317
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=7.1
- eightpoints/guzzle-bundle: ^7.2
- symfony/symfony: 3.4.*
This package is not auto-updated.
Last update: 2025-03-22 17:45:51 UTC
README
A tool to make it easier to implement the Kong CE solution on a Symfony project
Dependencies
- PHP >= 7.1
- Symfony 3.4.*
- Guzzle Client ^7.2
Installation
You'll be able to get the package with the following command composer require adaniloff/kong-user-bundle
.
Then follow these steps:
<?php /** In AppKernel */ $bundles = [ // add the following line new \Adaniloff\KongUserBundle\AdaniloffKongUserBundle(), ];
Configure a guzzle client:
# in app/config/config.yml eight_points_guzzle: clients: api_kong: # The admin base url, port included ; it will be defined later base_url: '%kong_user.host%' options: headers: Accept: 'application/json' Content-type: 'application/json'
Update your security config:
# in app/config/security.yml security: providers: # add this provider kong_user: id: Adaniloff\KongUserBundle\Security\KongUserProvider firewalls: main: guard: # add this authenticator authenticators: - Adaniloff\KongUserBundle\Security\KongAuthenticator
And add the bundle default configuration:
adaniloff_kong_user: kong_host: url: "http://localhost:8000" auth: type: "key-auths"
You can make a good usage of php bin/console config:dump-reference adaniloff_kong_user
to understand the configuration !
Example
Let's say you have the following Kong configuration :
# A consumer with a username `Aladdin` :
### curl http://kong:8001/consumers
{"next":null,"data":[{"custom_id":null,"created_at":1538573756,"username":"Aladdin","id":"0de8a9b0-xxx-xxx-xxx-148bda37091f"}]}
# And some auth process like key-auth : ...
### curl http://kong:8001/key-auths
{"total":1,"data":[{"id":"63cb981b-xxxx-xxxx-xxxx-6f7b3aa89d15","created_at":1538573769066,"key":"ZRJuTVjbMqZK67A0T4BbJAgrqVNgOQaP","consumer_id":"0de8a9b0-xxx-xxx-xxx-148bda37091f"}]}
# ... or basic-auth, with a password `OpenSesame`
### curl http://kong:8001/basic-auths
{"total":1,"data":[{"created_at":1538635575626,"id":"83fbc811-1cc4-4fba-a006-39a195cf282f","username":"Aladdin","password":"02ae45bb86dac5bb1a2174fc3f2e8449c488a981","consumer_id":"0de8a9b0-0e89-450e-be1e-148bda37091f"}]}
Then you should be able to make the following requests :
# Key Auth request, with an auth key defined as "x-apikey"
curl -i -X GET --url http://localhost:8000/ --header 'Host: my.custom.server.com' -H 'x-apikey: ZRJuTVjbMqZK67A0T4BbJAgrqVNgOQaP'
# Basic Auth request
curl -i -X GET --url http://localhost:8000/ --header 'Host: my.custom.server.com' -H 'Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l'
See also ...
- Learn more about the basic auth plugin
- Learn more about the key auth plugin