Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: support Feishu OAuth Provider (#9745)

Arvin Xu846a7a5986d0
diff --git a/docs/self-hosting/environment-variables/auth.mdx b/docs/self-hosting/environment-variables/auth.mdx
index 34c0b1a66a0..fc3b8575518 100644
--- a/docs/self-hosting/environment-variables/auth.mdx
+++ b/docs/self-hosting/environment-variables/auth.mdx
@@ -3,6 +3,7 @@ title: LobeChat Authentication Service Environment Variables
description: >-
Explore the essential environment variables for configuring authentication services in LobeChat, including OAuth SSO, NextAuth settings, and provider-specific details.
+
tags:
- Authentication Service
- OAuth SSO
@@ -279,6 +280,22 @@ LobeChat provides a complete authentication service capability when deployed. Th
- Default: `-`
- Example: `https://your-instance.okta.com`
+### Feishu
+
+#### `AUTH_FEISHU_APP_ID`
+
+- Type: Required
+- Description: App ID of the Feishu application.
+- Default: `-`
+- Example: `cli_9f7b1e1e1e1e1e1e`
+
+#### `AUTH_FEISHU_APP_SECRET`
+
+- Type: Required
+- Description: App Secret of the Feishu application.
+- Default: `-`
+- Example: `AlHxxX1e1e1e1e1e1e1e1e1e1e1e1e1e`
+
### Generic OIDC
#### `AUTH_GENERIC_OIDC_ID`
diff --git a/src/libs/next-auth/sso-providers/feishu.ts b/src/libs/next-auth/sso-providers/feishu.ts
new file mode 100644
index 00000000000..d28b4a4510d
--- /dev/null
+++ b/src/libs/next-auth/sso-providers/feishu.ts
@@ -0,0 +1,83 @@
+import { customFetch } from 'next-auth';
+import type { OAuthConfig } from 'next-auth/providers';
+
+interface FeishuProfile {
+ avatar_big: string;
+ avatar_middle: string;
+ avatar_thumb: string;
+ avatar_url: string;
+ en_name: string;
+ name: string;
+ open_id: string;
+ tenant_key: string;
+ union_id: string;
+}
+
+interface FeishuProfileResponse {
+ data: FeishuProfile;
+}
+
+function Feishu(): OAuthConfig<FeishuProfileResponse> {
+ return {
+ authorization: {
+ params: {
+ scope: '',
+ },
+ url: 'https://accounts.feishu.cn/open-apis/authen/v1/authorize',
+ },
+ checks: ['state'],
+ client: {
+ token_endpoint_auth_method: 'client_secret_post',
+ },
+ clientId: process.env.AUTH_FEISHU_APP_ID,
+ clientSecret: process.env.AUTH_FEISHU_APP_SECRET,
+ [customFetch]: (url, options = {}) => {
+ if (
+ url === 'https://open.feishu.cn/open-apis/authen/v2/oauth/token' &&
+ options.method === 'POST'
+ ) {
+ if (options?.headers) {
+ options.headers = {
+ ...options.headers,
+ 'content-type': 'application/json; charset=utf-8',
+ };
+ } else {
+ options.headers = {
+ 'content-type': 'application/json; charset=utf-8',
+ };
+ }
+
+ if (options.body instanceof URLSearchParams) {
+ options.body = JSON.stringify(Object.fromEntries(options.body));
+ }
+ }
+
+ return fetch(url, options);
+ },
+ id: 'feishu',
+ name: 'Feishu',
+ profile(profileResponse) {
+ const profile = profileResponse.data;
+
+ return {
+ id: profile.union_id,
+ image: profile.avatar_url,
+ name: profile.name,
+ providerAccountId: profile.union_id,
+ };
+ },
+ style: {
+ logo: 'https://p1-hera.feishucdn.com/tos-cn-i-jbbdkfciu3/268ec674a56a4510889f7f5ca14f1ba1~tplv-jbbdkfciu3-image:0:0.image',
+ },
+ token: 'https://open.feishu.cn/open-apis/authen/v2/oauth/token',
+ type: 'oauth',
+ userinfo: 'https://open.feishu.cn/open-apis/authen/v1/user_info',
+ };
+}
+
+const provider = {
+ id: 'feishu',
+ provider: Feishu(),
+};
+
+export default provider;
diff --git a/src/libs/next-auth/sso-providers/index.ts b/src/libs/next-auth/sso-providers/index.ts
index ee2777b8c9d..aba3e0094d1 100644
--- a/src/libs/next-auth/sso-providers/index.ts
+++ b/src/libs/next-auth/sso-providers/index.ts
@@ -5,6 +5,7 @@ import AzureAD from './azure-ad';
import Casdoor from './casdoor';
import CloudflareZeroTrust from './cloudflare-zero-trust';
import Cognito from './cognito';
+import Feishu from './feishu';
import GenericOIDC from './generic-oidc';
import Github from './github';
import Google from './google';
@@ -32,4 +33,5 @@ export const ssoProviders = [
Google,
Cognito,
Okta,
+ Feishu,
];