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.
This commit is contained in:
Cfp
2025-06-22 14:52:24 +02:00
parent 513c17eb76
commit 1baa5de4c0

View File

@ -1,16 +1,17 @@
// OIDC Server needs to have redirect url for /login/callback
import { getOIDCConfig } from "./lnv";
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, TOKEN_URL } = oidcConfig;
const { AUTH_URL, CLIENT_ID } = oidcConfig;
export { CLIENT_ID, TOKEN_URL };
export async function getAuthURL() {
const pkce = await generatePKCEChallenge();
const state = generateRandomString(16);
@ -59,6 +60,15 @@ async function sha256(input: string | undefined): Promise<ArrayBuffer> {
}
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);