Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d358f664d |
No files matched your search
@@ -23,6 +23,7 @@ Homarr supports multiple authentication options, from internal userbase (credent
|
||||
| AUTH_PROVIDERS | Select Which provider to use between *credentials*, *ldap* and *oidc*. <br /> Multiple providers can be enabled with by separating them with `,`, (ex. `AUTH_PROVIDERS=credentials,oidc`, it is highly recommended to just enable one provider). | credentials |
|
||||
| AUTH_LOGOUT_REDIRECT_URL | URL to redirect to after clicking logging out. | --- |
|
||||
| AUTH_SESSION_EXPIRY_TIME | Time for the session to time out. Can be set as pure number, which will automatically be used in seconds, or followed by s, m, h or d for seconds, minutes, hours or days. (ex: "30m") | "30d" |
|
||||
| AUTH_COOKIE_PREFIX | Prefix used for all authentication cookies (session, csrf, callback, pkce, state, nonce). Change this if you run another Auth.js/NextAuth app on the same hostname as Homarr (browsers scope cookies by host, not by port) to avoid cookie name collisions. Only letters, numbers, hyphens and underscores are allowed. | `homarr` |
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="credentials" label="Credentials Provider" default>
|
||||
|
||||
@@ -395,6 +395,7 @@ All available values are listed on the [artifacthub](https://artifacthub.io/pack
|
||||
| env.AUTH_LDAP_USERNAME_FILTER_EXTRA_ARG | string | `nil` | Extra arguments for user search filter (& based) |
|
||||
| env.AUTH_LDAP_USER_MAIL_ATTRIBUTE | string | `"mail"` | Attribute used for mail field |
|
||||
| env.AUTH_LOGOUT_REDIRECT_URL | string | `nil` | URL to redirect to after clicking logging out. |
|
||||
| env.AUTH_COOKIE_PREFIX | string | `"homarr"` | Prefix used for all authentication cookies. Change if you run another Auth.js/NextAuth app on the same hostname to avoid cookie name collisions. Only letters, numbers, hyphens and underscores. |
|
||||
| env.AUTH_OIDC_AUTO_LOGIN | string | `"false"` | Automatically redirect to OIDC login |
|
||||
| env.AUTH_OIDC_CLIENT_NAME | string | `"OIDC"` | Display name of provider (in login screen) |
|
||||
| env.AUTH_OIDC_GROUPS_ATTRIBUTE | string | `"groups"` | Attribute used for groups (roles) claim |
|
||||
|
||||
@@ -20,6 +20,24 @@ import { expireDateAfter, generateSessionToken, sessionTokenCookieName } from ".
|
||||
|
||||
const logger = createLogger({ module: "authConfiguration" });
|
||||
|
||||
// All Auth.js cookies are prefixed with AUTH_COOKIE_PREFIX (default "homarr") so
|
||||
// Homarr's cookie jar is isolated from any other Auth.js/NextAuth app on the
|
||||
// same hostname (browsers scope cookies by host, not by port).
|
||||
// See https://github.com/homarr-labs/homarr/issues/5773
|
||||
const createCookies = (useSecureCookies: boolean) => {
|
||||
const prefix = env.AUTH_COOKIE_PREFIX;
|
||||
const securePrefix = useSecureCookies ? "__Secure-" : "";
|
||||
const hostPrefix = useSecureCookies ? "__Host-" : "";
|
||||
return {
|
||||
sessionToken: { name: sessionTokenCookieName },
|
||||
csrfToken: { name: `${hostPrefix}${prefix}.csrf-token` },
|
||||
callbackUrl: { name: `${securePrefix}${prefix}.callback-url` },
|
||||
pkceCodeVerifier: { name: `${securePrefix}${prefix}.pkce.cooldown` },
|
||||
state: { name: `${securePrefix}${prefix}.state` },
|
||||
nonce: { name: `${securePrefix}${prefix}.nonce` },
|
||||
};
|
||||
};
|
||||
|
||||
// See why it's unknown in the [...nextauth]/route.ts file
|
||||
export const createConfiguration = (
|
||||
provider: SupportedAuthProvider | "unknown",
|
||||
@@ -41,11 +59,7 @@ export const createConfiguration = (
|
||||
},
|
||||
},
|
||||
trustHost: true,
|
||||
cookies: {
|
||||
sessionToken: {
|
||||
name: sessionTokenCookieName,
|
||||
},
|
||||
},
|
||||
cookies: createCookies(useSecureCookies),
|
||||
adapter,
|
||||
providers: filterProviders([
|
||||
Credentials(createCredentialsConfiguration(db)),
|
||||
|
||||
@@ -28,6 +28,11 @@ export const env = createEnv({
|
||||
AUTH_LOGOUT_REDIRECT_URL: z.string().url().optional(),
|
||||
AUTH_SESSION_EXPIRY_TIME: createDurationSchema("30d"),
|
||||
AUTH_PROVIDERS: authProvidersSchema,
|
||||
AUTH_COOKIE_PREFIX: z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(/^[a-zA-Z0-9-_]+$/, "AUTH_COOKIE_PREFIX must only contain letters, numbers, hyphens and underscores")
|
||||
.default("homarr"),
|
||||
...(authProviders.includes("oidc")
|
||||
? {
|
||||
AUTH_OIDC_ISSUER: z.string().url(),
|
||||
|
||||
@@ -4,9 +4,11 @@ import { generateSecureRandomToken } from "@homarr/common/server";
|
||||
import type { Database } from "@homarr/db";
|
||||
|
||||
import { getCurrentUserPermissionsAsync } from "./callbacks";
|
||||
import { env } from "./env";
|
||||
|
||||
// Default of authjs
|
||||
export const sessionTokenCookieName = "authjs.session-token";
|
||||
// Prefixed (AUTH_COOKIE_PREFIX, default "homarr") to avoid cookie collisions
|
||||
// with other Auth.js apps on the same host. See https://github.com/homarr-labs/homarr/issues/5773
|
||||
export const sessionTokenCookieName = `${env.AUTH_COOKIE_PREFIX}.session-token`;
|
||||
|
||||
export const expireDateAfter = (seconds: number) => {
|
||||
return new Date(Date.now() + seconds * 1000);
|
||||
|
||||
Reference in new issue
Block a user