且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Node JS对Google API进行身份验证

更新时间:2021-12-24 15:17:44

3腿Google OAuth虚拟指南.

从字面上看,您需要了解的所有信息都在此页面上 https://developers.google.com /identity/protocols/OAuth2WebServer .阅读两次,您将成为OAuth忍者.总之,它说...

Literally everything you need to know is on this single page https://developers.google.com/identity/protocols/OAuth2WebServer . Read it twice and you'll be an OAuth ninja. In summary, it says ...

  1. 使用4个查询参数构造一个account.google.com网址:-
  1. Construct an accounts.google.com URL with 4 query params :-
  1. client_id标识您的应用
  2. scope说出您要求的权限
  3. redirect_uri告诉Google将结果重定向到用户浏览器的位置
  4. response_type=code说您想要验证码
  1. client_id to identify your app
  2. scope to say what permissions you're asking for
  3. redirect_uri to tell Google where to redirect the user's browser with the result
  4. response_type=code to say you want an Auth Code

  • 将用户的浏览器重定向到该URL
  • 在用户登录时喝一口咖啡,选择他的Google帐户并授予权限,直到最终...
  • 用户的浏览器被重定向回应用程序的redirect_uri,查询参数为code,这是一次性的身份验证代码
  • 将身份验证代码发布到Google的令牌端点
  • 解析JSON响应以获取访问令牌
  • 在"authorization:bearer access_token" http标头中使用访问令牌,以用于后续的Google API请求
  • redirect the user's browser to that URL
  • Have a sip of coffee while the user logs in, chooses his Google account, and grants permission, until eventually ...
  • The user's browser gets redirected back to your app's redirect_uri, with a query param of code which is the one-time Auth Code
  • Post the Auth Code to Google's token endpoint
  • Parse the JSON response to get the Access Token
  • Use the Access Token in a "authorization: bearer access_token" http header for your subsequent Google API requests
  • 如果您访问 https://developers.google.com/oauthplayground/,则可以运行通过在线步骤,了解各种URL和响应是什么样的.

    If you go to https://developers.google.com/oauthplayground/ you can run through the steps online to see what the various URLs and responses look like.