【问题标题】:Kong API Gateway session plugin with user info带有用户信息的 Kong API 网关会话插件
【发布时间】:2021-05-20 17:45:32
【问题描述】:

我正在尝试将授权/身份验证从我的上游服务抽象到 Kong API 网关中。以前,我使用 express + passport 来处理会话。每当用户使用其凭据登录时,将创建一个会话,并将其用户信息附加到 req 对象 (req.user)。

目前,我正在使用API keys + session + serverless functions 来比较映射到 Kong 容器的文件中的用户密码(使用 bycrypt lua 库)。客户端将使用 API 密钥发送初始登录(使用用户名和密码)请求以登录,无服务器函数将比较密码哈希,如果所有通过,会话将被创建。

但是,我的问题是,有没有办法将用户信息存储到会话数据库中,以便我的上游服务可以请求该信息以确保附加到登录用户的会话在任何给定时间都有效?

任何与 Kong 无关的想法都将不胜感激!

【问题讨论】:

    标签: session api-gateway kong


    【解决方案1】:

    在 Kong 上创建新会话时,您可以显式提供用于标识会话的唯一 Key(默认由 KONG 自己创建)。 当密码检查通过并且您在 Kong 上生成会话时,您可以创建自己的唯一密钥并在创建会话时使用该密钥。

        Kong_admin = 'http://localhost:8001'
    
        kong_session = {'key': 'any-unique-combination'}
        #any unique combination which you would like to use for identifying the session
    
        user = 'test-user@dummy.com'
        
        #create a session for this dummy user using your key
        response = requests.post('%s/consumers/%s/jwt' % (Kong_admin, user),data=kong_session)
    
        
        #Once the session is created you can find it using
        
        resp = requests.get('%s/consumers/%s/jwt/any-unique-combination' % (Kong_admin, user))
        
        # you can use this key in your token payload so your upstream service can decrypt the 
        # payload and get this key and you can store this key in your database mapped with 
        # user during session creation.
        # with this you ll be able to decrypt any session payload , get a key and then query 
        # it on database at any point of time
    

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 1970-01-01
      • 2019-05-31
      • 2020-08-25
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      相关资源
      最近更新 更多