feat: add oidc to admin panel

This commit is contained in:
DecDuck
2025-05-08 15:29:50 +10:00
parent 19ff73cc30
commit bfa2c0a641
17 changed files with 91 additions and 44 deletions
-1
View File
@@ -27,7 +27,6 @@ export default defineNitroPlugin(async (_nitro) => {
}
}
// Add providers based on their position in the application settings
const configuredProviderList =
await applicationSettings.get("metadataProviders");
+12 -10
View File
@@ -1,28 +1,30 @@
import { AuthMec } from "@prisma/client";
import { OIDCManager } from "../internal/oidc";
export const enabledAuthManagers: {
simple: boolean;
oidc: OIDCManager | undefined;
[AuthMec.Simple]: boolean;
[AuthMec.OpenID]: OIDCManager | undefined;
} = {
simple: false,
oidc: undefined,
[AuthMec.Simple]: false,
[AuthMec.OpenID]: undefined,
};
const initFunctions: {
[K in keyof typeof enabledAuthManagers]: () => Promise<any>;
[K in keyof typeof enabledAuthManagers]: () => Promise<unknown>;
} = {
oidc: OIDCManager.prototype.create,
simple: async () => {
[AuthMec.OpenID]: OIDCManager.prototype.create,
[AuthMec.Simple]: async () => {
const disabled = process.env.DISABLE_SIMPLE_AUTH as string | undefined;
return !disabled;
},
};
export default defineNitroPlugin(async (nitro) => {
export default defineNitroPlugin(async () => {
for (const [key, init] of Object.entries(initFunctions)) {
try {
const object = await init();
if (!object) break;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(enabledAuthManagers as any)[key] = object;
console.log(`enabled auth: ${key}`);
} catch (e) {
@@ -31,7 +33,7 @@ export default defineNitroPlugin(async (nitro) => {
}
// Add every other auth mechanism here, and fall back to simple if none of them are enabled
if (!enabledAuthManagers.oidc) {
enabledAuthManagers.simple = true;
if (!enabledAuthManagers[AuthMec.OpenID]) {
enabledAuthManagers[AuthMec.Simple] = true;
}
});