eac039bba4
- Introduced OIDC configuration options in config.example.yaml. - Added OIDC client initialization and routes for OIDC login, callback, and exchange. - Implemented OIDC login service to handle user authentication via OIDC. - Created frontend components for OIDC login and callback handling. - Updated user creation logic to support OIDC users and their identities. - Enhanced error handling for OIDC login processes.
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { clearSession, writeSession, type AuthSession } from "@/lib/auth"
|
|
import { request } from "@/lib/api/client"
|
|
|
|
export type LoginRequest = {
|
|
username: string
|
|
password: string
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|