Skip to content

Commit 636bc26

Browse files
authored
Add doc for SAML SSO (#385)
1 parent d9f11f1 commit 636bc26

10 files changed

Lines changed: 98 additions & 4 deletions

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
- Discord Sign-In
5656
- Apple Sign-In
5757
- OIDC Auth Provider Sign-In
58+
- SAML SSO Sign-In (Node.js environment only) [SAML SSO Setup Doc](https://auth.valuemelody.com/saml-sso-setup.html)
5859
- <b>Multi-Factor Authentication</b> [How to setup MFA](https://auth.valuemelody.com/q_a.html#how-to-setup-mfa)
5960
- Email MFA
6061
- OTP MFA
@@ -68,6 +69,7 @@
6869
- change_email
6970
- reset_mfa
7071
- manage_passkey
72+
- saml_sso_[idp_name]
7173
- <b>Organization</b>:
7274
- Branding config override
7375
- Organization users
@@ -106,6 +108,7 @@
106108
- Manage Scopes
107109
- Manage Roles
108110
- Manage Organizations
111+
- Manage SAML SSO IDPs
109112
- Manage Logs
110113
- Admin Panel Access Control [Custom Role Access for the Admin Panel](https://auth.valuemelody.com/admin-panel-setup.html#custom-role-access-for-the-admin-panel)
111114

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ actions:
2020
- text: Social Sign-In Provider Setup
2121
link: /social-sign-in-provider-setup.html
2222
type: secondary
23+
- text: SAML SSO Setup
24+
link: /saml-sso-setup.html
25+
type: secondary
2326
- text: Admin Panel Setup
2427
link: /admin-panel-setup.html
2528
type: primary

docs/auth-server-configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Melody Auth offers a range of customizable options to tailor the authentication
9898
- **Default:** []
9999
- **Description:** A list of origins that are allowed to use embedded auth APIs.
100100

101+
### ENABLE_SAML_SSO_AS_SP
102+
- **Default:** false
103+
- **Description:** Toggles the SAML SSO as a Service Provider (SP) feature. If `true`, users can sign in with configured SAML SSO.
104+
101105
## Auth Configs
102106

103107
### AUTHORIZATION_CODE_EXPIRES_IN

docs/saml-sso-setup.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SAML SSO Setup
2+
3+
SAML SSO is currently supported only in the Node.js environment of Melody Auth.
4+
5+
## 1. Generate SAML SP certificate and key
6+
7+
```bash
8+
npm run node:saml:secret:generate
9+
```
10+
11+
## 2. Enable SAML SSO in `wrangler.toml`
12+
Ensure that SAML SSO as a Service Provider (SP) is enabled in your server/wrangler.toml configuration file:
13+
14+
```toml
15+
ENABLE_SAML_SSO_AS_SP=true
16+
```
17+
18+
## 3. Register a SAML Identity Provider (IdP) via Admin Panel
19+
20+
- Go to admin panel
21+
- Click "Manage SAML"
22+
- Click "Create" button
23+
- Define a unique name for the IDP, and fill in necessary information
24+
- Click "Save" button
25+
26+
## 4. Trigger Login via SAML SSO in the Frontend
27+
28+
Use the loginRedirect function provided by your Melody Auth frontend SDK (e.g., @melody-auth/react) to initiate the login process:
29+
30+
```
31+
const {
32+
loginRedirect
33+
} = useAuth()
34+
35+
loginRedirect({
36+
locale: locale || undefined, org: 'default',
37+
policy: 'saml_sso_[idp_name]' # Replace [idp_name] with the name of the IDP you created in admin panel
38+
})
39+
```

docs/zh/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ actions:
2020
- text: 社交登录提供商设置
2121
link: /zh/social-sign-in-provider-setup.html
2222
type: secondary
23+
- text: SAML SSO 设置
24+
link: /zh/saml-sso-setup.html
25+
type: secondary
2326
- text: 管理面板设置
2427
link: /zh/admin-panel-setup.html
2528
type: primary

docs/zh/auth-server-configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ Melody Auth 提供了一系列可自定义选项,以便您根据实际需求
9898
- **默认值:** []
9999
- **说明:** 允许使用嵌入式认证 API 的前端应用源列表。
100100

101+
### ENABLE_SAML_SSO_AS_SP
102+
- **默认值:** false
103+
- **说明:** 是否启用 SAML SSO 作为服务提供方(SP)功能。若设为 `true`,用户可通过配置的 SAML SSO 登录。
101104

102105
## 认证相关配置
103106

docs/zh/saml-sso-setup.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SAML SSO 设置
2+
3+
SAML SSO 当前仅在 Melody Auth 的 Node.js 环境中支持。
4+
5+
## 1. 生成 SAML SP 证书和密钥
6+
7+
```bash
8+
npm run node:saml:secret:generate
9+
```
10+
11+
## 2. 在 wrangler.toml 中启用 SAML SSO
12+
确保在服务器的 server/wrangler.toml 配置文件中启用了作为服务提供方(SP)的 SAML SSO:
13+
14+
```toml
15+
ENABLE_SAML_SSO_AS_SP=true
16+
```
17+
18+
## 3. 通过管理面板注册一个 SAML 身份提供商(IdP)
19+
20+
- 进入管理面板
21+
- 点击 “管理 SAML”
22+
- 点击 “创建” 按钮
23+
- 为 IDP 定义一个唯一名称,并填写必要信息
24+
- 点击 “保存” 按钮
25+
26+
## 4. 在前端触发 SAML SSO 登录
27+
28+
使用 Melody Auth 前端 SDK(例如 @melody-auth/react)提供的 loginRedirect 函数来发起登录流程:
29+
30+
```
31+
const {
32+
loginRedirect
33+
} = useAuth()
34+
35+
loginRedirect({
36+
locale: locale || undefined, org: 'default',
37+
policy: 'saml_sso_[idp_name]' # 将 [idp_name] 替换为你在管理面板中创建的 IDP 名称
38+
})
39+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "melody-auth",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "A turnkey OAuth & authentication system.",
55
"license": "MIT",
66
"author": "Baozier",

server/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ENABLE_USER_ATTRIBUTE=false
3232
BLOCKED_POLICIES=[] # A list of policy names that should be blocked (change_password, change_email, reset_mfa, manage_passkey, update_info), preventing end users from triggering them
3333
ENABLE_PASSWORDLESS_SIGN_IN=false # Please set up your mailer first https://auth.valuemelody.com/email-provider-setup.html. Setting this option to true will automatically override ENABLE_SIGN_UP, ENABLE_PASSWORD_SIGN_IN, ENABLE_PASSWORD_RESET, ALLOW_PASSKEY_ENROLLMENT to false. Also, make sure to disable email MFA in order to use this feature.
3434
EMBEDDED_AUTH_ORIGINS=[] # List of origins that are allowed to use embedded auth APIs.
35-
ENABLE_SAML_SSO_AS_SP=false # Experimental feature, do not use
35+
ENABLE_SAML_SSO_AS_SP=false # Experimental feature, only support in Node.js environment
3636

3737
# Auth
3838
AUTHORIZATION_CODE_EXPIRES_IN=300

0 commit comments

Comments
 (0)