Skip to main content

Okta 提供商 SSO 配置

🌐 Okta provider SSO configuration

Page summary:

Okta 是一个单点登录(SSO)提供商,允许用户通过其 Okta 账户使用在 auth.providers 数组中配置的 OAuth2 凭据登录和注册 Strapi。

🌐 Okta is an SSO provider that allows users to sign in and sign up to Strapi through their Okta account using OAuth2 credentials configured in the auth.providers array.

本页面解释了如何为单点登录 (SSO) 功能 设置 Okta 提供程序。

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

Prerequisites

你已阅读如何配置 SSO 指南

🌐 You have read the How to configure SSO guide.

安装

🌐 Installation

安装 passport-okta-oauth20

terminal
yarn add passport-okta-oauth20

配置示例

🌐 Configuration example

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

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

Caution

在设置 OKTA_DOMAIN 环境变量时,确保包含协议(例如,https://example.okta.com)。如果不这样做,你将陷入重定向循环。

🌐 When setting the OKTA_DOMAIN environment variable, make sure to include the protocol (e.g., https://example.okta.com). If you do not, you will end up in a redirect loop.

/config/admin.js

const OktaOAuth2Strategy = require("passport-okta-oauth20").Strategy;

module.exports = ({ env }) => ({
auth: {
// ...
providers: [
{
uid: "okta",
displayName: "Okta",
icon: "https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium-thumbnail.png",
createStrategy: (strapi) =>
new OktaOAuth2Strategy(
{
clientID: env("OKTA_CLIENT_ID"),
clientSecret: env("OKTA_CLIENT_SECRET"),
audience: env("OKTA_DOMAIN"),
scope: ["openid", "email", "profile"],
callbackURL:
strapi.admin.services.passport.getStrategyCallbackURL("okta"),
},
(accessToken, refreshToken, profile, done) => {
done(null, {
email: profile.email,
username: profile.username,
});
}
),
},
],
},
});
On this page