支持自部署需求管理、交付流程与飞书集成
This commit is contained in:
1 parent
2149aeb6ed
commit
51a2e548f2
152 files changed
+8652
-6394
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { appPath } from '@/lib/base-path';
|
||||
import { sessionCookie } from '@/lib/server/auth';
|
||||
import { applicationOrigin } from '@/lib/server/database';
|
||||
import { completeFeishuAuth, consumeFeishuState, FeishuAuthError, feishuStateCookie } from '@/lib/server/feishu-auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
export async function GET(request: Request) {
|
||||
const headers = new Headers({ 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' });
|
||||
let binding = false;
|
||||
try {
|
||||
const state = consumeFeishuState(request);
|
||||
binding = Boolean(state.account_id);
|
||||
headers.append('Set-Cookie', feishuStateCookie(''));
|
||||
const result = await completeFeishuAuth(request, state);
|
||||
if (result.token) headers.append('Set-Cookie', sessionCookie(result.token, request));
|
||||
headers.set('Location', applicationOrigin() + appPath(result.returnTo + (result.bound ? '?bound=1' : '')));
|
||||
} catch (error) {
|
||||
const code = error instanceof FeishuAuthError ? error.code : 'failed';
|
||||
headers.set('Location', applicationOrigin() + appPath(`${binding ? '/account/feishu' : '/login'}?feishuError=${code}`));
|
||||
}
|
||||
return new Response(null, { status: 303, headers });
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { appPath } from '@/lib/base-path';
|
||||
import { assertSameOrigin, AuthError } from '@/lib/server/auth';
|
||||
import { applicationOrigin } from '@/lib/server/database';
|
||||
import { beginFeishuAuth, FeishuAuthError } from '@/lib/server/feishu-auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
export async function POST(request: Request) {
|
||||
let intent = 'login';
|
||||
try {
|
||||
assertSameOrigin(request);
|
||||
const raw = await request.text();
|
||||
if (raw.length > 8192) throw new FeishuAuthError('failed');
|
||||
const form = new URLSearchParams(raw);
|
||||
intent = form.get('intent') || 'login';
|
||||
const result = beginFeishuAuth(request, intent, form.get('next'));
|
||||
return new Response(null, { status: 303, headers: { Location: result.url, 'Set-Cookie': result.cookie, 'Cache-Control': 'no-store' } });
|
||||
} catch (error) {
|
||||
const code = error instanceof FeishuAuthError ? error.code : error instanceof AuthError && error.status === 429 ? 'rate_limited' : error instanceof AuthError && error.status === 403 ? 'source' : 'failed';
|
||||
return new Response(null, { status: 303, headers: { Location: applicationOrigin() + appPath(`${intent === 'bind' ? '/account/feishu' : '/login'}?feishuError=${code}`), 'Cache-Control': 'no-store' } });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { assertSameOrigin, authFailure, jsonResponse, loginWithPassword, readJsonObject, sessionCookie } from '@/lib/server/auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
assertSameOrigin(request);
|
||||
const body = await readJsonObject(request);
|
||||
const { user, token } = await loginWithPassword(body.username, body.password, request);
|
||||
return jsonResponse({ user }, 200, sessionCookie(token, request));
|
||||
} catch (error) { return authFailure(error); }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { assertSameOrigin, authFailure, jsonResponse, logoutCurrentSession, sessionCookie } from '@/lib/server/auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
assertSameOrigin(request);
|
||||
await logoutCurrentSession();
|
||||
return jsonResponse({ ok: true }, 200, sessionCookie('', request));
|
||||
} catch (error) { return authFailure(error); }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { authFailure, jsonResponse, requireApiUser } from '@/lib/server/auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
try { return jsonResponse({ user: await requireApiUser({ allowPasswordChange: true }) }); }
|
||||
catch (error) { return authFailure(error); }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { assertSameOrigin, authFailure, changeAccountPassword, jsonResponse, readJsonObject, requireApiUser, sessionCookie } from '@/lib/server/auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
assertSameOrigin(request);
|
||||
const current = await requireApiUser({ allowPasswordChange: true });
|
||||
const body = await readJsonObject(request);
|
||||
const { user, token } = await changeAccountPassword(current.userId, body.currentPassword, body.newPassword);
|
||||
return jsonResponse({ user }, 200, sessionCookie(token, request));
|
||||
} catch (error) { return authFailure(error); }
|
||||
}
|
||||
Reference in new issue
Block a user