@lobehub/chat 1.77.18 → 1.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 1.78.0](https://github.com/lobehub/lobe-chat/compare/v1.77.18...v1.78.0)
6
+
7
+ <sup>Released on **2025-04-09**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Add Keycloak SSO provider support.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Add Keycloak SSO provider support, closes [#7342](https://github.com/lobehub/lobe-chat/issues/7342) ([f739425](https://github.com/lobehub/lobe-chat/commit/f739425))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.77.18](https://github.com/lobehub/lobe-chat/compare/v1.77.17...v1.77.18)
6
31
 
7
32
  <sup>Released on **2025-04-09**</sup>
package/README.md CHANGED
@@ -333,7 +333,7 @@ In addition, these plugins are not limited to news aggregation, but can also ext
333
333
  | [MintbaseSearch](https://lobechat.com/discover/plugin/mintbasesearch)<br/><sup>By **mintbase** on **2024-12-31**</sup> | Find any NFT data on the NEAR Protocol.<br/>`crypto` `nft` |
334
334
  | [Bing_websearch](https://lobechat.com/discover/plugin/Bingsearch-identifier)<br/><sup>By **FineHow** on **2024-12-22**</sup> | Search for information from the internet base BingApi<br/>`bingsearch` |
335
335
 
336
- > 📊 Total plugins: [<kbd>**46**</kbd>](https://lobechat.com/discover/plugins)
336
+ > 📊 Total plugins: [<kbd>**45**</kbd>](https://lobechat.com/discover/plugins)
337
337
 
338
338
  <!-- PLUGIN LIST -->
339
339
 
package/README.zh-CN.md CHANGED
@@ -326,7 +326,7 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
326
326
  | [MintbaseSearch](https://lobechat.com/discover/plugin/mintbasesearch)<br/><sup>By **mintbase** on **2024-12-31**</sup> | 在 NEAR 协议上查找任何 NFT 数据。<br/>`加密货币` `nft` |
327
327
  | [必应网页搜索](https://lobechat.com/discover/plugin/Bingsearch-identifier)<br/><sup>By **FineHow** on **2024-12-22**</sup> | 通过 BingApi 搜索互联网上的信息<br/>`bingsearch` |
328
328
 
329
- > 📊 Total plugins: [<kbd>**46**</kbd>](https://lobechat.com/discover/plugins)
329
+ > 📊 Total plugins: [<kbd>**45**</kbd>](https://lobechat.com/discover/plugins)
330
330
 
331
331
  <!-- PLUGIN LIST -->
332
332
 
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "features": [
5
+ "Add Keycloak SSO provider support."
6
+ ]
7
+ },
8
+ "date": "2025-04-09",
9
+ "version": "1.78.0"
10
+ },
2
11
  {
3
12
  "children": {
4
13
  "improvements": [
@@ -0,0 +1,119 @@
1
+ ---
2
+ title: Configuring Keycloak Authentication Service in LobeChat
3
+ description: >-
4
+ Learn how to configure the Keycloak authentication service in LobeChat,
5
+ including deployment, creation, permission settings, and environment
6
+ variables.
7
+ tags:
8
+ - Keycloak Authentication
9
+ - Environment Variable Configuration
10
+ - Single Sign-On
11
+ - LobeChat
12
+ ---
13
+
14
+ # Configuring Keycloak Authentication Service in LobeChat
15
+
16
+ [Keycloak](https://www.keycloak.org/) is an open-source identity and access management solution that provides single sign-on, identity brokering, and social login features, suitable for modern applications and services.
17
+
18
+ <Callout type={'tip'}>
19
+ If you want to privately deploy Keycloak, we recommend using it together with LobeChat via Docker Compose deployment for easier service management.
20
+ </Callout>
21
+
22
+ ## Keycloak Configuration Process
23
+
24
+ If you deploy using a local network IP, this guide assumes:
25
+
26
+ - Your LobeChat database version IP/port is `http://LOBECHAT_IP:3210`.
27
+ - Your privately deployed Keycloak domain is `http://KEYCLOAK_IP:8080`.
28
+
29
+ If you deploy using a public network, this guide assumes:
30
+
31
+ - Your LobeChat database version domain is `https://lobe.example.com`.
32
+ - Your privately deployed Keycloak domain is `https://lobe-auth-api.example.com`.
33
+
34
+ <Steps>
35
+ ### Create Keycloak Realm and Client
36
+
37
+ Access your privately deployed Keycloak admin console (default is `http://localhost:8080/admin`) and log in with the administrator account.
38
+
39
+ 1. Create a new Realm
40
+ - Click the dropdown menu in the upper left corner and select "Create Realm"
41
+ - Enter a name, such as "LobeChat", then click "Create"
42
+
43
+ 2. Create a Client
44
+ - Select "Clients" from the left menu, then click "Create client"
45
+ - Fill in the following information:
46
+ - Client ID: `lobechat`
47
+ - Client type: `OpenID Connect`
48
+ - Click "Next"
49
+ - On the "Capability config" page:
50
+ - Enable "Client authentication"
51
+ - Enable "Standard flow"
52
+ - Click "Next"
53
+ - On the "Login settings" page:
54
+ - Valid redirect URIs:
55
+ - Local development environment: `http://localhost:3210/api/auth/callback/keycloak`
56
+ - Local network IP deployment: `http://LOBECHAT_IP:3210/api/auth/callback/keycloak`
57
+ - Public environment: `https://lobe.example.com/api/auth/callback/keycloak`
58
+ - Web origins: Add your LobeChat domain or IP
59
+ - Click "Save"
60
+
61
+ 3. Get Client Secret
62
+ - On the client details page, switch to the "Credentials" tab
63
+ - Copy the "Client secret" value, which will be needed later
64
+
65
+ ### Configure Users and Roles (Optional)
66
+
67
+ 1. Create Users
68
+ - Select "Users" from the left menu, then click "Add user"
69
+ - Fill in the user information and click "Create"
70
+ - On the user details page, switch to the "Credentials" tab
71
+ - Set a password, and disable the "Temporary" option if needed
72
+ - Click "Set Password" to save
73
+
74
+ 2. Create Roles and Permissions
75
+ - Select "Realm roles" from the left menu
76
+ - Click "Create role"
77
+ - Create necessary roles, such as "admin", "user", etc.
78
+ - Assign roles to users: On the user details page, switch to the "Role mapping" tab and assign appropriate roles
79
+
80
+ ### Disable Registration (Optional)
81
+
82
+ To ensure the security of your application, it's recommended to control Keycloak's registration functionality.
83
+
84
+ 1. Select "Realm settings" from the left menu
85
+ 2. Switch to the "Login" tab
86
+ 3. In the "User registration" section, disable the "User registration" option
87
+ 4. Click "Save" to save the settings
88
+
89
+ <Callout type={'warning'}>
90
+ If registration is not disabled, anyone might be able to register and log in to your application. Please configure according to your security requirements.
91
+ </Callout>
92
+
93
+ ### Configure Environment Variables
94
+
95
+ Set the obtained client ID and client secret as `AUTH_KEYCLOAK_ID` and `AUTH_KEYCLOAK_SECRET` in the LobeChat environment variables.
96
+
97
+ Configure the LobeChat environment variable `AUTH_KEYCLOAK_ISSUER` as:
98
+
99
+ - `http://localhost:8080/realms/LobeChat` for local development environment
100
+ - `http://KEYCLOAK_IP:8080/realms/LobeChat` for privately deployed Keycloak on a local network
101
+ - `https://lobe-auth-api.example.com/realms/LobeChat` for Keycloak deployed in a public environment
102
+
103
+ When deploying LobeChat, you need to configure the following environment variables:
104
+
105
+ | Environment Variable | Type | Description |
106
+ | ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
107
+ | `NEXT_AUTH_SECRET` | Required | Key used to encrypt Auth.js session tokens. You can generate a key using: `openssl rand -base64 32` |
108
+ | `NEXT_AUTH_SSO_PROVIDERS` | Required | Select the single sign-on provider for LobeChat. For Keycloak, fill in `keycloak`. |
109
+ | `AUTH_KEYCLOAK_ID` | Required | Keycloak client ID |
110
+ | `AUTH_KEYCLOAK_SECRET` | Required | Keycloak client secret |
111
+ | `AUTH_KEYCLOAK_ISSUER` | Required | OpenID Connect issuer URL for the Keycloak provider, in the format `{keycloak_url}/realms/{realm_name}` |
112
+ | `NEXTAUTH_URL` | Required | This URL specifies the callback address for Auth.js during OAuth verification. Only needed when the default generated redirect address is incorrect. `https://lobe.example.com/api/auth` |
113
+
114
+ <Callout type={'tip'}>
115
+ Visit [📘 Environment Variables](/zh/docs/self-hosting/environment-variables/auth#keycloak) for details on related variables.
116
+ </Callout>
117
+ </Steps>
118
+
119
+ <Callout type={'info'}>After successful deployment, users will be able to authenticate through Keycloak and use LobeChat.</Callout>
@@ -0,0 +1,116 @@
1
+ ---
2
+ title: 在 LobeChat 中配置 Keycloak 身份验证服务
3
+ description: 学习如何在 LobeChat 中配置 Keycloak 身份验证服务,包括部署、创建、设置权限和环境变量。
4
+ tags:
5
+ - Keycloak 身份验证
6
+ - 环境变量配置
7
+ - 单点登录
8
+ - LobeChat
9
+ ---
10
+
11
+ # 配置 Keycloak 身份验证服务
12
+
13
+ [Keycloak](https://www.keycloak.org/) 是一个开源的身份和访问管理解决方案,提供单点登录、身份代理和社交登录等功能,适用于现代应用和服务。
14
+
15
+ <Callout type={'tip'}>
16
+ 若你想要私有部署 Keycloak,我们建议你将之与 LobeChat 一同使用 Docker Compose 部署,这样可以更方便地管理服务。
17
+ </Callout>
18
+
19
+ ## Keycloak 配置流程
20
+
21
+ 若你使用局域网 IP 部署,下文假设:
22
+
23
+ - 你的 LobeChat 数据库版本 IP / 端口为 `http://LOBECHAT_IP:3210`。
24
+ - 你私有部署 Keycloak,其域名为 `http://KEYCLOAK_IP:8080`。
25
+
26
+ 若你使用公网部署,下文假设:
27
+
28
+ - 你的 LobeChat 数据库版本域名为 `https://lobe.example.com`。
29
+ - 你私有部署 Keycloak,其域名为 `https://lobe-auth-api.example.com`。
30
+
31
+ <Steps>
32
+ ### 创建 Keycloak 领域和客户端
33
+
34
+ 访问你私有部署的 Keycloak 管理控制台(默认为 `http://localhost:8080/admin`),使用管理员账号登录。
35
+
36
+ 1. 创建新领域(Realm)
37
+ - 点击左上角的下拉菜单,选择 "Create Realm"
38
+ - 输入名称,例如 "LobeChat",然后点击 "Create"
39
+
40
+ 2. 创建客户端(Client)
41
+ - 在左侧菜单中选择 "Clients",然后点击 "Create client"
42
+ - 填写以下信息:
43
+ - Client ID: `lobechat`
44
+ - Client type: `OpenID Connect`
45
+ - 点击 "Next"
46
+ - 在 "Capability config" 页面:
47
+ - 启用 "Client authentication"
48
+ - 启用 "Standard flow"
49
+ - 点击 "Next"
50
+ - 在 "Login settings" 页面:
51
+ - Valid redirect URIs:
52
+ - 本地开发环境:`http://localhost:3210/api/auth/callback/keycloak`
53
+ - 局域网 IP 部署:`http://LOBECHAT_IP:3210/api/auth/callback/keycloak`
54
+ - 公网环境:`https://lobe.example.com/api/auth/callback/keycloak`
55
+ - Web origins: 添加你的 LobeChat 域名或 IP
56
+ - 点击 "Save"
57
+
58
+ 3. 获取客户端密钥
59
+ - 在客户端详情页,切换到 "Credentials" 选项卡
60
+ - 复制 "Client secret" 的值,后续需要用到
61
+
62
+ ### 配置用户和角色(可选)
63
+
64
+ 1. 创建用户
65
+ - 在左侧菜单中选择 "Users",然后点击 "Add user"
66
+ - 填写用户信息,点击 "Create"
67
+ - 在用户详情页,切换到 "Credentials" 选项卡
68
+ - 设置密码,并根据需要禁用 "Temporary" 选项
69
+ - 点击 "Set Password" 保存
70
+
71
+ 2. 创建角色和权限
72
+ - 在左侧菜单中选择 "Realm roles"
73
+ - 点击 "Create role"
74
+ - 创建所需角色,如 "admin"、"user" 等
75
+ - 为用户分配角色:在用户详情页,切换到 "Role mapping" 选项卡,分配相应角色
76
+
77
+ ### 关闭注册(可选)
78
+
79
+ 为了保证你的应用安全,建议控制 Keycloak 的注册功能。
80
+
81
+ 1. 在左侧菜单中选择 "Realm settings"
82
+ 2. 切换到 "Login" 选项卡
83
+ 3. 在 "User registration" 部分,禁用 "User registration" 选项
84
+ 4. 点击 "Save" 保存设置
85
+
86
+ <Callout type={'warning'}>
87
+ 如果不关闭注册功能,任何人都可能注册并登录你的应用,请根据你的安全需求进行配置。
88
+ </Callout>
89
+
90
+ ### 配置环境变量
91
+
92
+ 将获取到的客户端 ID 和客户端密钥,设为 LobeChat 环境变量中的 `AUTH_KEYCLOAK_ID` 和 `AUTH_KEYCLOAK_SECRET`。
93
+
94
+ 配置 LobeChat 环境变量中 `AUTH_KEYCLOAK_ISSUER` 为:
95
+
96
+ - `http://localhost:8080/realms/LobeChat`,若你是本地开发环境
97
+ - `http://KEYCLOAK_IP:8080/realms/LobeChat`,若你是局域网私有部署的 Keycloak
98
+ - `https://lobe-auth-api.example.com/realms/LobeChat`,若你是公网环境部署的 Keycloak
99
+
100
+ 在部署 LobeChat 时,你需要配置以下环境变量:
101
+
102
+ | 环境变量 | 类型 | 描述 |
103
+ | ------------------------- | -- | ------------------------------------------------------------------------------------------------ |
104
+ | `NEXT_AUTH_SECRET` | 必选 | 用于加密 Auth.js 会话令牌的密钥。您可以使用以下命令生成秘钥: `openssl rand -base64 32` |
105
+ | `NEXT_AUTH_SSO_PROVIDERS` | 必选 | 选择 LoboChat 的单点登录提供商。使用 Keycloak 请填写 `keycloak`。 |
106
+ | `AUTH_KEYCLOAK_ID` | 必选 | Keycloak 客户端 ID |
107
+ | `AUTH_KEYCLOAK_SECRET` | 必选 | Keycloak 客户端密钥 |
108
+ | `AUTH_KEYCLOAK_ISSUER` | 必选 | Keycloak 提供程序的 OpenID Connect 颁发者 URL,格式为 `{keycloak_url}/realms/{realm_name}` |
109
+ | `NEXTAUTH_URL` | 必选 | 该 URL 用于指定 Auth.js 在执行 OAuth 验证时的回调地址,当默认生成的重定向地址发生不正确时才需要设置。`https://lobe.example.com/api/auth` |
110
+
111
+ <Callout type={'tip'}>
112
+ 前往 [📘 环境变量](/zh/docs/self-hosting/environment-variables/auth#keycloak) 可查阅相关变量详情。
113
+ </Callout>
114
+ </Steps>
115
+
116
+ <Callout type={'info'}>部署成功后,用户将可以通过 Keycloak 身份认证并使用 LobeChat。</Callout>
@@ -52,6 +52,8 @@ Currently supported identity verification services include:
52
52
  <Card href={'/docs/self-hosting/advanced/auth/next-auth/authelia'} title={'Authelia'} />
53
53
 
54
54
  <Card href={'/docs/self-hosting/advanced/auth/next-auth/logto'} title={'Logto'} />
55
+
56
+ <Card href={'/docs/self-hosting/advanced/auth/next-auth/keycloak'} title={'Keycloak'} />
55
57
  </Cards>
56
58
 
57
59
  Click on the links to view the corresponding platform's configuration documentation.
@@ -73,6 +75,7 @@ The order corresponds to the display order of the SSO providers.
73
75
  | Logto | `logto` |
74
76
  | Microsoft Entra ID | `microsoft-entra-id` |
75
77
  | ZITADEL | `zitadel` |
78
+ | Keycloak | `keycloak` |
76
79
 
77
80
  ## Other SSO Providers
78
81
 
@@ -49,6 +49,8 @@ LobeChat 与 Clerk 做了深度集成,能够为用户提供一个更加安全
49
49
  <Card href={'/zh/docs/self-hosting/advanced/auth/next-auth/authelia'} title={'Authelia'} />
50
50
 
51
51
  <Card href={'/zh/docs/self-hosting/advanced/auth/next-auth/logto'} title={'Logto'} />
52
+
53
+ <Card href={'/zh/docs/self-hosting/advanced/auth/next-auth/keycloak'} title={'Keycloak'} />
52
54
  </Cards>
53
55
 
54
56
  点击即可查看对应平台的配置文档。
@@ -70,6 +72,7 @@ LobeChat 与 Clerk 做了深度集成,能够为用户提供一个更加安全
70
72
  | Logto | `logto` |
71
73
  | Microsoft Entra ID | `microsoft-entra-id` |
72
74
  | ZITADEL | `zitadel` |
75
+ | Keycloak | `keycloak` |
73
76
 
74
77
  ## 其他 SSO 提供商
75
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.77.18",
3
+ "version": "1.78.0",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -6,6 +6,7 @@ import Casdoor from './casdoor';
6
6
  import CloudflareZeroTrust from './cloudflare-zero-trust';
7
7
  import GenericOIDC from './generic-oidc';
8
8
  import Github from './github';
9
+ import Keycloak from './keycloak';
9
10
  import Logto from './logto';
10
11
  import MicrosoftEntraID from './microsoft-entra-id';
11
12
  import WeChat from './wechat';
@@ -24,4 +25,5 @@ export const ssoProviders = [
24
25
  Casdoor,
25
26
  MicrosoftEntraID,
26
27
  WeChat,
28
+ Keycloak,
27
29
  ];
@@ -0,0 +1,25 @@
1
+ import Keycloak from 'next-auth/providers/keycloak';
2
+
3
+ import { CommonProviderConfig } from './sso.config';
4
+
5
+ const provider = {
6
+ id: 'keycloak',
7
+ provider: Keycloak({
8
+ ...CommonProviderConfig,
9
+ // Specify auth scope, at least include 'openid email'
10
+ authorization: { params: { scope: 'openid email profile' } },
11
+ clientId: process.env.AUTH_KEYCLOAK_ID,
12
+ clientSecret: process.env.AUTH_KEYCLOAK_SECRET,
13
+ issuer: process.env.AUTH_KEYCLOAK_ISSUER,
14
+ profile(profile) {
15
+ return {
16
+ email: profile.email,
17
+ id: profile.sub,
18
+ name: profile.name,
19
+ providerAccountId: profile.sub,
20
+ };
21
+ },
22
+ }),
23
+ };
24
+
25
+ export default provider;