Design Prot Merge #1
@@ -16,5 +16,8 @@ SESSION_SECRET=change-me-to-a-long-random-string
|
|||||||
# SESSION_REFRESH_THRESHOLD_SECONDS=30
|
# SESSION_REFRESH_THRESHOLD_SECONDS=30
|
||||||
# AUTH_FLOW_TTL_SECONDS=600
|
# AUTH_FLOW_TTL_SECONDS=600
|
||||||
|
|
||||||
|
# Dev already allows a plain-HTTP issuer. Set this only to allow it in a production build (never with a public issuer).
|
||||||
|
# AUTH_ALLOW_INSECURE_HTTP=true
|
||||||
|
|
||||||
# Backend API base URL (used from later parts)
|
# Backend API base URL (used from later parts)
|
||||||
API_BASE_URL=http://localhost:5111
|
API_BASE_URL=http://localhost:5111
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as client from 'openid-client';
|
import * as client from 'openid-client';
|
||||||
import { EncryptJWT, jwtDecrypt } from 'jose';
|
import { EncryptJWT, jwtDecrypt } from 'jose';
|
||||||
|
import { dev } from '$app/environment';
|
||||||
import { authConfig } from '$lib/server/config';
|
import { authConfig } from '$lib/server/config';
|
||||||
import type { SessionUser } from '$lib/types';
|
import type { SessionUser } from '$lib/types';
|
||||||
|
|
||||||
@@ -16,13 +17,12 @@ export interface Session extends SessionUser {
|
|||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
let configPromise: Promise<client.Configuration> | null = null;
|
let configPromise: Promise<client.Configuration>;
|
||||||
|
|
||||||
export function getOidcConfig(): Promise<client.Configuration> {
|
export function getOidcConfig(): Promise<client.Configuration> {
|
||||||
configPromise ??= (async () => {
|
configPromise ??= (async () => {
|
||||||
const issuer = new URL(authConfig.issuer);
|
const issuer = new URL(authConfig.issuer);
|
||||||
const options =
|
const insecureAllowed = (dev || authConfig.allowInsecureHttp) && issuer.protocol === 'http:';
|
||||||
issuer.protocol === 'http:' ? { execute: [client.allowInsecureRequests] } : undefined;
|
const options = insecureAllowed ? { execute: [client.allowInsecureRequests] } : undefined;
|
||||||
|
|
||||||
const secret = authConfig.clientSecret;
|
const secret = authConfig.clientSecret;
|
||||||
return secret
|
return secret
|
||||||
@@ -32,8 +32,7 @@ export function getOidcConfig(): Promise<client.Configuration> {
|
|||||||
return configPromise;
|
return configPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyPromise: Promise<Uint8Array> | null = null;
|
let keyPromise: Promise<Uint8Array>;
|
||||||
|
|
||||||
function sessionKey(): Promise<Uint8Array> {
|
function sessionKey(): Promise<Uint8Array> {
|
||||||
keyPromise ??= crypto.subtle
|
keyPromise ??= crypto.subtle
|
||||||
.digest('SHA-256', new TextEncoder().encode(authConfig.sessionSecret))
|
.digest('SHA-256', new TextEncoder().encode(authConfig.sessionSecret))
|
||||||
|
|||||||
@@ -40,5 +40,8 @@ export const authConfig = {
|
|||||||
},
|
},
|
||||||
get flowTtlSeconds() {
|
get flowTtlSeconds() {
|
||||||
return positiveInt(env.AUTH_FLOW_TTL_SECONDS, 600);
|
return positiveInt(env.AUTH_FLOW_TTL_SECONDS, 600);
|
||||||
|
},
|
||||||
|
get allowInsecureHttp() {
|
||||||
|
return env.AUTH_ALLOW_INSECURE_HTTP === 'true';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user