Revert "feat(makelore): add platform oidc login"

This reverts commit 7236def07d.
This commit is contained in:
brother7 committed 2026-10-11 12:04:01 +08:00
1 parent f2a0eefc9e
commit e28beff3a6
11 files changed
+10 -475

No files matched your search

+4 -20
View File
@@ -2,11 +2,8 @@ export const NIANCODE_APP_PROTOCOL = 'niancode';
export type NianCodeDeepLink = {
type: 'desktop-auth-callback';
/** Legacy desktop auth callbacks carry a request id. OIDC callbacks use state. */
requestId?: string;
requestId: string;
url: string;
code?: string;
state?: string;
} | { type: 'cloud-agent'; slug: string; url: string }
| { type: 'teacher-preview'; draftRevision: number; url: string };
@@ -32,7 +29,6 @@ const SENSITIVE_QUERY_KEYS = new Set([
'device_secret',
'token',
]);
const AUTH_CALLBACK_QUERY_KEYS = new Set(['request_id', 'code', 'state']);
export function parseNianCodeDeepLinkUrl(rawUrl: string): NianCodeDeepLink | null {
let url: URL;
@@ -71,27 +67,15 @@ export function parseNianCodeDeepLinkUrl(rawUrl: string): NianCodeDeepLink | nul
}
}
if ([...url.searchParams.keys()].some((key) => !AUTH_CALLBACK_QUERY_KEYS.has(key))) {
const requestId = url.searchParams.get('request_id')?.trim();
if (!requestId || requestId.length > 128) {
return null;
}
const requestId = url.searchParams.get('request_id')?.trim() || undefined;
if (requestId && requestId.length > 128) return null;
const code = url.searchParams.get('code')?.trim() || undefined;
const state = url.searchParams.get('state')?.trim() || undefined;
if (Boolean(code) !== Boolean(state) || (code && code.length > 4096) || (state && state.length > 512)) {
return null;
}
// The platform OIDC redirect is registered as niancode://auth/callback and
// therefore returns code/state without the legacy request_id parameter.
if (!requestId && !(code && state)) return null;
return {
type: 'desktop-auth-callback',
...(requestId ? { requestId } : {}),
requestId,
url: rawUrl,
...(code ? { code, state } : {}),
};
}
+2 -60
View File
@@ -65,7 +65,6 @@ import { createReleaseUtilityPreparer } from '../services/release-utility-proces
import { createStaticArtifactSnapshot } from '../services/static-release-server';
import {
consumeWorksSquareStartupRuntimeCleanupRequired,
commitWorksSquareSessionFromTokenPayload,
getWorksSquareSessionRestoreStatus,
getWorksSquareSessionSnapshot,
initializeWorksSquareSession,
@@ -74,11 +73,7 @@ import {
} from '../services/works-square-session';
import { shouldUseSecureWorksSquareSessionPersistence } from '../services/works-square-session-persistence-policy';
import { initializeRememberedPassword } from '../services/remembered-password';
import {
clearManagedWorksSquareRuntimeBestEffort,
ensureManagedWorksSquareRuntimeClean,
} from '../services/works-square-runtime';
import { completePlatformAuthorization } from '../services/platform-auth';
import { clearManagedWorksSquareRuntimeBestEffort } from '../services/works-square-runtime';
import { WorksSquareDesignWorkspace } from '../image-workspace/works-square-workspace';
import type { DesignWorkspaceModule } from '../image-workspace/module';
import {
@@ -212,12 +207,6 @@ let releaseJobs: ReleaseJobManager | null = null;
let codingProducts: CodingProductComposition | null = null;
let windowIpcBindings: ReturnType<typeof registerIpcHandlers> | null = null;
let unsubscribeAuthSession: (() => void) | null = null;
let platformAuthReady = false;
let queuedPlatformAuthCallback: {
requestId: string | null;
code: string;
state: string;
} | null = null;
const mainWindowFocusState = createMainWindowFocusState();
const quitLifecycleState = createQuitLifecycleState();
const launchDeepLinkUrl = findNianCodeDeepLinkUrl(process.argv);
@@ -376,33 +365,6 @@ function requestMainWindowFocus(reason: string): void {
logger.debug(`Main window is not ready yet; deferring focus for ${reason}`);
}
function completePlatformAuthCallback(callback: {
requestId: string | null;
code: string;
state: string;
}): void {
void (async () => {
// Match the password/mobile login path: clean the previous account's
// derived runtime before making the new account active. Keeping the
// authorization pending until cleanup succeeds lets the user retry after
// a transient local cleanup failure.
await ensureManagedWorksSquareRuntimeClean({
codingProducts: codingProducts ?? undefined,
imageWorkspace: imageWorkspaceModule ?? undefined,
});
const payload = await completePlatformAuthorization(
callback.requestId,
callback.code,
callback.state,
);
await commitWorksSquareSessionFromTokenPayload(payload);
requestMainWindowFocus('platform OIDC callback');
})().catch((error) => {
logger.warn('[auth] Platform OIDC callback was not completed', error);
requestMainWindowFocus('platform OIDC callback failure');
});
}
function handleAppDeepLinkActivation(rawUrl: string): boolean {
const deepLink = parseNianCodeDeepLinkUrl(rawUrl);
if (!deepLink) {
@@ -416,21 +378,7 @@ function handleAppDeepLinkActivation(rawUrl: string): boolean {
queueTeacherPreviewRevision(deepLink.draftRevision);
mainWindow?.webContents.send('navigate', '/coding-teacher-preview?draftRevision=' + deepLink.draftRevision);
} else {
if (deepLink.code && deepLink.state) {
const callback = {
requestId: deepLink.requestId ?? null,
code: deepLink.code,
state: deepLink.state,
};
if (platformAuthReady) {
completePlatformAuthCallback(callback);
} else {
queuedPlatformAuthCallback = callback;
logger.debug('[auth] Queued platform OIDC callback until session restore is ready');
}
} else {
logger.info(`Received Makelore app link: type=${deepLink.type}, request_id=${deepLink.requestId ?? 'none'}`);
}
logger.info(`Received Makelore app link: type=${deepLink.type}, request_id=${deepLink.requestId}`);
}
requestMainWindowFocus('app deep link');
return true;
@@ -716,12 +664,6 @@ async function initialize(): Promise<void> {
}, 'expired persisted session during startup');
});
}
platformAuthReady = true;
if (queuedPlatformAuthCallback) {
const callback = queuedPlatformAuthCallback;
queuedPlatformAuthCallback = null;
completePlatformAuthCallback(callback);
}
if (!isE2EMode) {
projectProgressSync = createProjectProgressSync(codingProjectStore);
const activateProgrammingServices = (): void => {