mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-28 01:10:54 +01:00
* wip: add provider field to sqlite user table * feat: disable invites when credentials provider is not used * wip: add migration for provider field in user table with sqlite * wip: remove fields that can not be modified by non credential users * wip: make username, mail and avatar disabled instead of hidden * wip: external users membership of group cannot be managed manually * feat: add alerts to inform about disabled fields and managing group members * wip: add mysql migration for provider on user table * chore: fix format issues * chore: address pull request feedback * fix: build issue * fix: deepsource issues * fix: tests not working * feat: restrict login to specific auth providers * chore: address pull request feedback * fix: deepsource issue
40 lines
1.2 KiB
TypeScript
40 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 { 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(db, data).catch(() => null);
|
|
}
|
|
|
|
return await authorizeWithBasicCredentialsAsync(db, data);
|
|
},
|
|
}) satisfies CredentialsConfiguration;
|