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

页面摘要: GitHub 提供方设置可为 Strapi 的 Users & Permissions 功能启用 OAuth 身份验证,需要配置 GitHub OAuth 应用和 Strapi 提供方设置。

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

WARNING

GitHub 配置

NOTE

Github 不接受 localhost URL。

使用 ngrok 来提供后端应用。

ngrok http 1337

别忘了使用生成的 ngrok URL 更新后端配置文件 config/server.js 中的服务器 URL,以及你的前端应用中的服务器 URL(如果你使用 react 登录示例应用,则为环境变量 REACT_APP_BACKEND_URL)。

  1. 访问 OAuth Apps 列表页面 https://github.com/settings/developers
  2. 点击 New OAuth App(新建 OAuth 应用)按钮
  3. 填写信息(替换为你自己的 ngrok URL):
    • Application name(应用名称):Strapi GitHub auth
    • Homepage URL(主页 URL):https://65e60559.ngrok.io
    • Application description(应用描述):Strapi provider auth description
    • Authorization callback URL(授权回调 URL):https://65e60559.ngrok.io/api/connect/github/callback

Strapi 配置

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

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