c246b85a9e
- Implemented request ID handling in various services and handlers to improve traceability of requests. - Added new AuthOptions endpoint to expose WxWork and OIDC configuration options. - Updated message and event logging to include request ID for better debugging. - Enhanced login form to dynamically show available authentication options based on server configuration. - Introduced utility functions for normalizing and ensuring valid request IDs. - Updated tests to verify request ID functionality in message sending and event logging.
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import { clearSession, writeSession, type AuthSession } from "@/lib/auth"
|
|
import { request } from "@/lib/api/client"
|
|
|
|
export type LoginRequest = {
|
|
username: string
|
|
password: string
|
|
}
|
|
|
|
export type AuthOptions = {
|
|
wxworkEnabled: boolean
|
|
oidcEnabled: boolean
|
|
}
|
|
|
|
export async function fetchAuthOptions() {
|
|
return request<AuthOptions>("/api/auth/options", {
|
|
skipAuth: true,
|
|
})
|
|
}
|
|
|
|
export async function loginWithPassword(payload: LoginRequest) {
|
|
const data = await request<AuthSession>("/api/auth/login", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
skipAuth: true,
|
|
})
|
|
writeSession(data)
|
|
return data
|
|
}
|
|
|
|
export async function exchangeWxWorkTicket(ticket: string) {
|
|
const data = await request<AuthSession>("/api/auth/wxwork_exchange", {
|
|
method: "POST",
|
|
body: JSON.stringify({ ticket }),
|
|
skipAuth: true,
|
|
})
|
|
writeSession(data)
|
|
return data
|
|
}
|
|
|
|
export async function exchangeOIDCTicket(ticket: string) {
|
|
const data = await request<AuthSession>("/api/auth/oidc_exchange", {
|
|
method: "POST",
|
|
body: JSON.stringify({ ticket }),
|
|
skipAuth: true,
|
|
})
|
|
writeSession(data)
|
|
return data
|
|
}
|
|
|
|
export async function fetchProfile() {
|
|
return request<AuthSession>("/api/auth/profile")
|
|
}
|
|
|
|
export async function logout() {
|
|
try {
|
|
await request("/api/auth/logout", {
|
|
method: "POST",
|
|
})
|
|
} finally {
|
|
clearSession()
|
|
}
|
|
}
|