美文网首页
糕dy带你玩kong-oauth2(dashboard+dock

糕dy带你玩kong-oauth2(dashboard+dock

作者: GoddyWu | 来源:发表于2018-11-02 11:10 被阅读0次

因为kong是基于API管理的,所以制作它的GUI是非常方便的,但是不要重复发明轮子,这里我们使用 https://github.com/PGBI/kong-dashboard 项目。关于oauth2的几种授权模式,建议读http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html

docker-compose.yml

version: '2.1'
services:
  kong-database:
    image: postgres:9.5
    environment:
      - POSTGRES_USER=kong
      - POSTGRES_DB=kong
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 30s
      timeout: 30s
      retries: 3
    restart: on-failure
  kong:
    image: kong:latest
    command: kong start --run-migrations
    depends_on:
      kong-database:
        condition: service_healthy
    healthcheck:
      test: "kong health"
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_DATABASE=kong
      - KONG_ADMIN_LISTEN=0.0.0.0:8001        
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8443:8443"
      - "8444:8444"
    restart: on-failure
  kong-dashboard:
    image: pgbi/kong-dashboard
    depends_on:
      kong:
        condition: service_healthy
    entrypoint: ./docker/entrypoint_dev.sh
    ports:
      - "8081:8080"
  kong-java:
    image: godbaby/kong-java:1.0
    ports:
      - "3000:3000"

参考:

使用docker-compose启动之后

dashboard启动较慢,稍等1-2分钟后访问http://localhost:8081

这里后续我们按照https://www.jianshu.com/p/814a5307632b 来操作。

1.创建service


注意host要是docker-compose对应服务的名称。

2.创建route

这时已经可以访问到资源服务的内容了。

3.为service添加插件

所有插件戳这里
oauth2的选项含义戳这里

简单一些,我们这里先只勾选并写下scopes 这时再此访问资源,则收到
{
    "error_description": "The access token is missing",
    "error": "invalid_request"
}

4.创建consumer

5.consumer下创建application

如果想用密码模式redirect_url可以随便填一下。如果是授权码模式,则需要填对应跳转网址。

6.使用Resource Owner Password Credentials获取token

点击我们的插件,里面可以找到自动生成的provision key 这里我们配置的username、password、authenticated_userid是随便写的,kong的oauth插件是需要我们自己开发一个backend(后端服务)来验证用户名密码的正确性。

相关文章

网友评论

      本文标题:糕dy带你玩kong-oauth2(dashboard+dock

      本文链接:https://www.haomeiwen.com/subject/uusqxqtx.html