adaniloff/kong-user-bundle

一个小型包,帮助您集成Kong解决方案。

安装: 312

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

类型:package

v1.0.3 2018-10-16 15:19 UTC

README

一个工具,用于在Symfony项目中更容易地实现Kong CE解决方案

依赖项

  • PHP >= 7.1
  • Symfony 3.4.*
  • Guzzle Client ^7.2

安装

您可以使用以下命令获取此包:composer require adaniloff/kong-user-bundle

然后按照以下步骤进行

<?php
/** In AppKernel */
$bundles = [
    // add the following line
    new \Adaniloff\KongUserBundle\AdaniloffKongUserBundle(),
];

配置Guzzle客户端

# 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'

更新您的安全配置

# 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

并添加包的默认配置

adaniloff_kong_user:
    kong_host:
        url: "https://:8000"
    auth:
        type: "key-auths"

您可以使用php bin/console config:dump-reference adaniloff_kong_user来理解配置!

示例

假设您有以下Kong配置

# 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"}]}

然后您应该能够执行以下请求

# Key Auth request, with an auth key defined as "x-apikey"
curl -i -X GET --url https://:8000/ --header 'Host: my.custom.server.com' -H 'x-apikey: ZRJuTVjbMqZK67A0T4BbJAgrqVNgOQaP'

# Basic Auth request
curl -i -X GET --url https://:8000/ --header 'Host: my.custom.server.com' -H 'Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l'

另请参阅...