Skip to main content

谷歌提供商单点登录配置

🌐 Google provider SSO configuration

Page summary:

在你的 Strapi 管理面板中将 Google 配置为 SSO 提供商,以允许用户使用其 Google 账户凭据登录和注册。

🌐 Configure Google as an SSO provider in your Strapi admin panel to allow users to sign in and sign up using their Google account credentials.

本页面说明了如何为单点登录 (SSO) 功能 设置 Google 提供商。

🌐 The present page explains how to setup the Google provider for the Single Sign-On (SSO) feature.

Prerequisites

你已阅读如何配置 SSO 指南

🌐 You have read the How to configure SSO guide.

安装

🌐 Installation

安装 passport-google-oauth2

terminal
yarn add passport-google-oauth2

配置示例

🌐 Configuration example

Google SSO 提供程序在 config/admin 文件auth.providers 数组中配置:

🌐 The Google SSO provider is configured in the auth.providers array of the config/admin file:

/config/admin.js

const GoogleStrategy = require("passport-google-oauth2");

module.exports = ({ env }) => ({
auth: {
// ...
providers: [
{
uid: "google",
displayName: "Google",
icon: "https://cdn2.iconfinder.com/data/icons/social-icons-33/128/Google-512.png",
createStrategy: (strapi) =>
new GoogleStrategy(
{
clientID: env("GOOGLE_CLIENT_ID"),
clientSecret: env("GOOGLE_CLIENT_SECRET"),
scope: [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
],
callbackURL:
strapi.admin.services.passport.getStrategyCallbackURL("google"),
},
(request, accessToken, refreshToken, profile, done) => {
done(null, {
email: profile.email,
firstname: profile.given_name,
lastname: profile.family_name,
});
}
),
},
],
},
});
On this page