Google 提供方在 Users & Permissions 中的设置

页面摘要: 通过在 Google Developer Console 中创建凭据并将其添加到提供方设置,为 Strapi Users & Permissions 配置 Google OAuth 身份验证。

本页介绍如何为 Users & Permissions 功能 设置 Google 提供方。

WARNING

Google 配置

NOTE

Google 接受 localhost URL。

无需使用 ngrok。

  1. 访问 Google Developer Console,地址为 https://console.developers.google.com/
  2. 在顶部菜单中点击 Select a project(选择项目)下拉菜单
  3. 然后点击 NEW PROJECT(新建项目)按钮
  4. 填写 Project name(项目名称)输入框并创建

应用程序创建需要等待几秒钟。

  1. 在项目下拉菜单中,选择你的新项目
  2. 在 APIs 卡片下点击 Go to APIs overview(转到 API 概览)
  3. 然后在左侧菜单中点击 Credentials(凭据)链接
  4. 点击 OAuth consent screen(OAuth 同意屏幕)按钮
  5. 选择 External(外部)并点击创建
  6. 填写 Application name(应用名称)并保存
  7. 然后点击 Create credentials(创建凭据)按钮
  8. 选择 OAuth client ID(OAuth 客户端 ID)选项
  9. 填写信息:
    • Name(名称):Strapi Auth
    • Authorized redirect URIs(已授权的重定向 URI):http://localhost:1337/api/connect/google/callback
  10. 点击你刚刚创建的客户端的 OAuth 2.0 Client IDs 名称
  11. 你应该能看到自己的 Application ID 和 secret,请将它们保存以备后用

Strapi 配置

  1. 访问 User & Permissions 提供方设置页面,地址为 http://localhost:1337/admin/settings/users-permissions/providers
  2. 点击 Google 提供方
  3. 填写以下信息(替换为你自己的客户端 ID 和密钥):
    • Enable:ON
    • Client ID:226437944084-o2mojv5i4lfnng9q8kq3jkf5v03avemk.apps.googleusercontent.com
    • Client Secret:aiTbMoiuJQflSBy6uQrfgsni
    • 指向你前端应用的重定向 URL:http://localhost:3000/connect/google/redirect

你的配置已完成。启动后端和 react 登录示例应用,访问 http://localhost:3000 并尝试连接到你所配置的提供方。