* wip: sso * feat: add ldap client and provider * feat: implement login form * feat: finish sso * fix: lint and format issue * chore: address pull request feedback * fix: build not working * fix: oidc is redirected to internal docker container hostname * fix: build not working * refactor: migrate to ldapts * fix: format and frozen lock file * fix: deepsource issues * fix: unit tests for ldap authorization not working * refactor: remove unnecessary args from dockerfile * chore: address pull request feedback * fix: use console instead of logger in auth env.mjs * fix: default value for auth provider of wrong type * fix: broken lock file * fix: format issue
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type Credentials from "@auth/core/providers/credentials";
|
|
|
|
import type { Database } from "@homarr/db";
|
|
import { validation } from "@homarr/validation";
|
|
|
|
import { adapter } from "../../adapter";
|
|
import { authorizeWithBasicCredentialsAsync } from "./authorization/basic-authorization";
|
|
import { authorizeWithLdapCredentialsAsync } from "./authorization/ldap-authorization";
|
|
|
|
type CredentialsConfiguration = Parameters<typeof Credentials>[0];
|
|
|
|
export const createCredentialsConfiguration = (db: Database) =>
|
|
({
|
|
type: "credentials",
|
|
name: "Credentials",
|
|
credentials: {
|
|
name: {
|
|
label: "Username",
|
|
type: "text",
|
|
},
|
|
password: {
|
|
label: "Password",
|
|
type: "password",
|
|
},
|
|
isLdap: {
|
|
label: "LDAP",
|
|
type: "checkbox",
|
|
},
|
|
},
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
async authorize(credentials) {
|
|
const data = await validation.user.signIn.parseAsync(credentials);
|
|
|
|
if (data.credentialType === "ldap") {
|
|
return await authorizeWithLdapCredentialsAsync(adapter, data).catch(() => null);
|
|
}
|
|
|
|
return await authorizeWithBasicCredentialsAsync(db, data);
|
|
},
|
|
}) satisfies CredentialsConfiguration;
|