From 1baa5de4c09fe49b233d094f43b2c2c3a1cdbe45 Mon Sep 17 00:00:00 2001 From: Cfp Date: Sun, 22 Jun 2025 14:52:24 +0200 Subject: [PATCH] fix: error on unsupported OIDC by server Don't crash with an error when the server is unavailable or the server doesn't provide/support an OIDC server. --- src/lib/services/oidc.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lib/services/oidc.ts b/src/lib/services/oidc.ts index da797f5..3d03d59 100644 --- a/src/lib/services/oidc.ts +++ b/src/lib/services/oidc.ts @@ -1,16 +1,17 @@ // OIDC Server needs to have redirect url for /login/callback -import { getOIDCConfig } from "./lnv"; - -const oidcConfig = await getOIDCConfig(); -if (!oidcConfig) { - throw new Error("Server does not support OIDC authentication"); -} -const { AUTH_URL, CLIENT_ID, TOKEN_URL } = oidcConfig; - -export { CLIENT_ID, TOKEN_URL }; +import { getOIDCConfig, hasCapability } from "./lnv"; export async function getAuthURL() { + if(!await hasCapability("auth")) { + throw new Error("Server does not support OIDC authentication"); + } + const oidcConfig = await getOIDCConfig(); + if (!oidcConfig) { + throw new Error("Server does not support OIDC authentication"); + } + const { AUTH_URL, CLIENT_ID } = oidcConfig; + const pkce = await generatePKCEChallenge(); const state = generateRandomString(16); @@ -59,6 +60,15 @@ async function sha256(input: string | undefined): Promise { } export async function getOIDCUser(code: string, codeVerifier: string) { + if(!await hasCapability("auth")) { + throw new Error("Server does not support OIDC authentication"); + } + const oidcConfig = await getOIDCConfig(); + if (!oidcConfig) { + throw new Error("Server does not support OIDC authentication"); + } + const { CLIENT_ID, TOKEN_URL } = oidcConfig; + const params = new URLSearchParams(); params.append("grant_type", "authorization_code"); params.append("code", code);