Skip to main content

Google 提供商 SSO 配置

¥Google provider SSO configuration

本页面说明如何为 单点登录 (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 :

¥Install passport-google-oauth2 :

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,
});
}
),
},
],
},
});