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.

✨ feat(oidc): register a dedicated lobot-desktop client for Lobot (#23506)

Lobehub Coder45cd693e4cb0
diff --git a/packages/const/src/desktop.test.ts b/packages/const/src/desktop.test.ts
new file mode 100644
index 00000000000..62fcd2df9e3
--- /dev/null
+++ b/packages/const/src/desktop.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest';
+
+import { isDesktopOidcClient } from './desktop';
+
+describe('isDesktopOidcClient', () => {
+ it('recognises both LobeHub Desktop and Lobot', () => {
+ expect(isDesktopOidcClient('lobehub-desktop')).toBe(true);
+ expect(isDesktopOidcClient('lobot-desktop')).toBe(true);
+ });
+
+ it('rejects other clients and missing ids', () => {
+ expect(isDesktopOidcClient('lobehub-mobile')).toBe(false);
+ expect(isDesktopOidcClient('lobehub-cli')).toBe(false);
+ expect(isDesktopOidcClient(undefined)).toBe(false);
+ expect(isDesktopOidcClient('')).toBe(false);
+ });
+});
diff --git a/packages/const/src/desktop.ts b/packages/const/src/desktop.ts
index af314c008b1..f3a075c09a9 100644
--- a/packages/const/src/desktop.ts
+++ b/packages/const/src/desktop.ts
@@ -9,3 +9,22 @@ export const DEFAULT_DESKTOP_HOTKEY_CONFIG: DesktopHotkeyConfig =
acc[item.id] = item.keys;
return acc;
}, {} as DesktopHotkeyConfig);
+
+/** OIDC client the LobeHub desktop app signs in with. */
+export const LOBEHUB_DESKTOP_CLIENT_ID = 'lobehub-desktop';
+
+/**
+ * OIDC client Lobot signs in with. Lobot is a separate desktop app, so it gets
+ * its own client instead of borrowing LobeHub Desktop's: its grants, sessions
+ * and token usage stay apart and either app can be revoked on its own.
+ */
+export const LOBOT_DESKTOP_CLIENT_ID = 'lobot-desktop';
+
+/** Desktop apps that sign in through the `/oidc/callback/desktop` handoff. */
+export const DESKTOP_OIDC_CLIENT_IDS: readonly string[] = [
+ LOBEHUB_DESKTOP_CLIENT_ID,
+ LOBOT_DESKTOP_CLIENT_ID,
+];
+
+export const isDesktopOidcClient = (clientId?: string | null): boolean =>
+ !!clientId && DESKTOP_OIDC_CLIENT_IDS.includes(clientId);
diff --git a/src/features/Auth/OAuthConsent/Consent/index.tsx b/src/features/Auth/OAuthConsent/Consent/index.tsx
index 545763aa404..22a5ee55a10 100644
--- a/src/features/Auth/OAuthConsent/Consent/index.tsx
+++ b/src/features/Auth/OAuthConsent/Consent/index.tsx
@@ -1,5 +1,6 @@
'use client';
+import { DESKTOP_OIDC_CLIENT_IDS } from '@lobechat/const';
import { Block, Button, Flexbox, Text } from '@lobehub/ui';
import React, { memo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -30,7 +31,12 @@ function getScopeDescription(scope: string, t: any, reviewKind?: 'acceptance' |
return t(`consent.scope.${scope.replace(':', '-')}`, scope);
}
-const BUILTIN_CLIENTS = new Set(['lobehub-desktop', 'lobehub-mobile', 'lobehub-market', 'toby']);
+const BUILTIN_CLIENTS = new Set([
+ ...DESKTOP_OIDC_CLIENT_IDS,
+ 'lobehub-mobile',
+ 'lobehub-market',
+ 'toby',
+]);
const ConsentClient = memo<ClientProps>(
({ acceptanceReview, uid, clientId, scopes, clientMetadata }) => {
diff --git a/src/libs/oidc-provider/config.test.ts b/src/libs/oidc-provider/config.test.ts
index 60db98f2b73..fccb7e5a9ca 100644
--- a/src/libs/oidc-provider/config.test.ts
+++ b/src/libs/oidc-provider/config.test.ts
@@ -39,6 +39,24 @@ describe('OIDC default clients', () => {
expect(names['lobehub-mobile']).toBe('Acme Mobile');
});
+ it('give Lobot its own desktop client that signs in through the desktop handoff', async () => {
+ vi.resetModules();
+ const { defaultClients } = await import('./config');
+ const desktop = defaultClients.find((c) => c.client_id === 'lobehub-desktop');
+ const lobot = defaultClients.find((c) => c.client_id === 'lobot-desktop');
+
+ expect(lobot).toMatchObject({
+ client_name: 'Lobot',
+ logo_uri: 'https://hub-apac-1.lobeobjects.space/lobot-desktop-icon.png',
+ grant_types: ['authorization_code', 'refresh_token'],
+ response_types: ['code'],
+ token_endpoint_auth_method: 'none',
+ });
+ expect(lobot?.redirect_uris).toEqual(desktop?.redirect_uris);
+ expect(lobot?.redirect_uris?.every((uri) => uri.endsWith('/oidc/callback/desktop'))).toBe(true);
+ expect(lobot?.post_logout_redirect_uris).toEqual(desktop?.post_logout_redirect_uris);
+ });
+
it('register the browser extension as a public PKCE client that can stay signed in', async () => {
vi.resetModules();
const { defaultClients } = await import('./config');
diff --git a/src/libs/oidc-provider/config.ts b/src/libs/oidc-provider/config.ts
index 84baa0fa581..6a132e5d7eb 100644
--- a/src/libs/oidc-provider/config.ts
+++ b/src/libs/oidc-provider/config.ts
@@ -5,6 +5,8 @@ import {
ACCEPTANCE_EXTENSION_IDS,
ACCEPTANCE_EXTENSION_SCOPE,
ACCEPTANCE_REVIEW_SCOPE,
+ LOBEHUB_DESKTOP_CLIENT_ID,
+ LOBOT_DESKTOP_CLIENT_ID,
} from '@lobechat/const';
import { type ClientMetadata } from 'oidc-provider';
import urlJoin from 'url-join';
@@ -19,36 +21,53 @@ const desktopAppOrigins = cloudAppOrigins.includes(new URL(appUrl).origin)
const marketBaseUrl = new URL(appEnv.MARKET_BASE_URL ?? 'https://market.lobehub.com').origin;
/**
- * Clients the open-source distribution registers itself.
+ * A desktop app signs in through the shared `/oidc/callback/desktop` handoff:
+ * the callback stores the code under the request's `state`, and the app polls
+ * it back with its PKCE verifier. Each app still has its own client, so its
+ * grants and tokens are told apart from the other desktop apps'.
*/
-const builtinClients: ClientMetadata[] = [
- {
- application_type: 'web',
- client_id: 'lobehub-desktop',
- client_name: `${BRANDING_NAME} Desktop`,
- // Only supports authorization code flow
- grant_types: ['authorization_code', 'refresh_token'],
+const desktopClient = (
+ client: Pick<ClientMetadata, 'client_id' | 'client_name' | 'logo_uri'>,
+): ClientMetadata => ({
+ application_type: 'web',
+ // Only supports authorization code flow
+ grant_types: ['authorization_code', 'refresh_token'],
- logo_uri: 'https://hub-apac-1.lobeobjects.space/lobehub-desktop-icon.png',
+ post_logout_redirect_uris: [
+ // Keep the legacy subdomain working while Cloud moves to the apex domain.
+ ...desktopAppOrigins.map((origin) => urlJoin(origin, '/oauth/logout')),
+ 'http://localhost:3210/oauth/logout',
+ ],
- post_logout_redirect_uris: [
- // Keep the legacy subdomain working while Cloud moves to the apex domain.
- ...desktopAppOrigins.map((origin) => urlJoin(origin, '/oauth/logout')),
- 'http://localhost:3210/oauth/logout',
- ],
+ // Desktop authorization callback - changed to web page path
+ redirect_uris: [
+ ...desktopAppOrigins.map((origin) => urlJoin(origin, '/oidc/callback/desktop')),
+ 'http://localhost:3210/oidc/callback/desktop',
+ ],
- // Desktop authorization callback - changed to web page path
- redirect_uris: [
- ...desktopAppOrigins.map((origin) => urlJoin(origin, '/oidc/callback/desktop')),
- 'http://localhost:3210/oidc/callback/desktop',
- ],
+ // Supports authorization code for obtaining tokens and refresh tokens
+ response_types: ['code'],
- // Supports authorization code for obtaining tokens and refresh tokens
- response_types: ['code'],
+ // Marked as public client with no secret
+ token_endpoint_auth_method: 'none',
- // Marked as public client with no secret
- token_endpoint_auth_method: 'none',
- },
+ ...client,
+});
+
+/**
+ * Clients the open-source distribution registers itself.
+ */
+const builtinClients: ClientMetadata[] = [
+ desktopClient({
+ client_id: LOBEHUB_DESKTOP_CLIENT_ID,
+ client_name: `${BRANDING_NAME} Desktop`,
+ logo_uri: 'https://hub-apac-1.lobeobjects.space/lobehub-desktop-icon.png',
+ }),
+ desktopClient({
+ client_id: LOBOT_DESKTOP_CLIENT_ID,
+ client_name: 'Lobot',
+ logo_uri: 'https://hub-apac-1.lobeobjects.space/lobot-desktop-icon.png',
+ }),
{
application_type: 'native', // Mobile uses native type