• 请不要在回答技术问题时复制粘贴 AI 生成的内容
whiplash211
V2EX  ›  程序员

OAuth 关于 state 的疑惑,求指教

  •  1
     
  •   whiplash211 · Nov 27, 2019 · 2073 views
    This topic created in 2376 days ago, the information mentioned may be changed or developed.

    实现 OAuth 第三方登录的时候遇到个问题,想请教下各位前辈。 如何验证从服务提供商返回的请求中的 state 参数与用户发起三方登录时的 state 是一致的,即如何在用户没有登录的时候进行标记从而保证第三方登录请求确实是这个用户(终端)发起的?

    4 replies    2019-11-27 18:50:32 +08:00
    whiplash211
        1
    whiplash211  
    OP
       Nov 27, 2019
    补充,看到一篇文章里有给出实现方式,但不会 node 不太明白这里的 req.session ( express-session 这个插件)本质上是如何实现的
    或者说其本质是如何判断 2 个请求属于同个 session 的


    ![image.png]( https://i.loli.net/2019/11/27/qnD421TBijumlwQ.png)
    ![image.png]( https://i.loli.net/2019/11/27/NiYEuoVyGlPeZIk.png)

    文章地址: https://shiya.io/how-to-do-3-legged-oauth-with-github-a-general-guide-by-example-with-node-js/
    whiplash211
        2
    whiplash211  
    OP
       Nov 27, 2019
    小弟困惑的点在于不知道怎么建立发起请求的客户端与 state 的对应关系,有做过 github 登录或者微信登录的老哥能解答一下🐴
    deepzz
        3
    deepzz  
       Nov 27, 2019 via iPhone
    发起三方登录的时候你根本不知道是谁要登录,只有从第三方获取用户信息的时候才知道谁在登录。state 可以携带一些其它标记信息 https://deepzz.com/post/what-is-oauth2-protocol.html
    whiplash211
        4
    whiplash211  
    OP
       Nov 27, 2019
    @deepzz 😹不是我不明白 state 干啥的,不过我现在知道怎么弄了,参考 flask 框架的 session 额外加个加密的 cookie 存 state,收到回调再验证
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2769 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:08 · PVG 13:08 · LAX 22:08 · JFK 01:08
    ♥ Do have faith in what you're doing.