首页 > 解决方案 > StackOverflow 是否使用 OpenID Connect 进行 Google 登录?

问题描述

我试图更好地了解 OAuth2 和 OpenID Connect,因此我决定在使用 Google 帐户登录 StackOverflow 时查看 Chrome 的开发人员工具中显示的内容。

点击 Google 按钮登录后,会发出以下 5 个网络请求:

请注意,我已经登录 Google 并且之前已授权 StackOverflow。

1) 204 POST https://stackoverflow.com/gps/event
    Request Payload:
        ...
        properties:
            location: "users_login"
            openid_provider: "google"

2) 302 POST https://stackoverflow.com/users/login?...
    Query String Parameters:
        ssrc: head
        returnurl: https://stackoverflow.com/
    Form Data:
        email: 
        password: 
        oauth_version: 2.0
        oauth_server: https://accounts.google.com/o/oauth2/auth
        openid_username: 
        openid_identifier: 

3) 302 GET https://accounts.google.com/o/oauth2/auth?...
    Query String Parameters:
        client_id: xxxx
        scope: profile email
        redirect_uri: https://stackauth.com/auth/oauth2/google
        state: {"sid":1,"st":"xxxx","ses":"xxxx"}
        response_type: code


4) 302 GET https://stackauth.com/auth/oauth2/google?...
    Query String Parameters:
        state: {"sid":1,"st":"xxxx","ses":"xxxx"}
        code: xxxx


5) 302 GET https://stackoverflow.com/users/oauth/google?...
    Query String Parameters:
        code: xxxx
        state: {"sid":1,"st":"xxxx","ses":"xxxx"}
        s: xxxx

从请求 1) 看来,使用了 OpenID Connect。但是再看请求 3),请求的范围是scope: profile email.

如果实际使用了 OpenID Connect,是否不会openid包含在范围内?没有它,token端点将不会返回一个id_token权利?

这是否意味着 StackOverflow 实际上并没有使用 OpenID Connect 来验证使用 Google 登录的用户,而是利用普通的旧 OAuth2?

如果是这样,我假设在 OpenID Connect 出现之前,普通的旧 OAuth2 通常用于身份验证(以安全方式)?

标签: authenticationoauth-2.0openid-connect

解决方案


看起来 StackOverflow 正在使用 Google 作为提供者进行简单的 OAuth 2.0 授权代码流。

请求 1) 将发送到 StackOverflow 服务器。这并不意味着什么。您可以看到,如果您在 Facebook 上按一下, openid_provider: "facebook"即使 Facebook 没有实现 OpenID Connect,您也会得到。

StackOverflow 正在实现类似的东西: https://developers.google.com/identity/sign-in/web/server-side-flow 但只是使用重定向而不是使用谷歌库

OAuth 2.0 授权代码流程解释: https ://aaronparecki.com/oauth-2-simplified/#web-server-apps


推荐阅读