feat: add oidc to admin panel

This commit is contained in:
DecDuck
2025-05-08 15:29:50 +10:00
parent 952df560ec
commit e3ed60feae
17 changed files with 89 additions and 43 deletions

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");

View File

@ -1,24 +1,25 @@
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<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();
@ -32,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;
}
});