- Serve multiple domains (RP IDs) from one instance: host-based dispatch, per-domain credentials and sessions, domains managed at runtime in the admin UI — previously one RP per instance - Cross-domain sign-in via Related Origin Requests: per-domain related-origins list with a served .well-known/webauthn document - Explicit per-domain origin lists with shell-glob wildcards (**. for apex + any subdomain depth, *. for one level), editable in the admin UI with validation and self-lockout guards - Per-domain auth hosts: the account/admin UI can live on a different host per domain, no longer confined to subdomains of a single RP - CLI: 'paskia init <rp-id [rp-name]' initializes or adds a domain to an existing database; 'paskia migrate' converts legacy databases BREAKING CHANGES (v2.0): - Database schema: config is now per-domain and credentials/sessions carry an rp_id — existing databases must be converted with 'paskia migrate' - Origins are now explicit: main implicitly allowed every subdomain of the RP; configure '**.' origins to reproduce that behavior - CLI: the flat '--rp-id/--rp-name/--origin/--auth/--save' flags are replaced by the 'init' and 'migrate' subcommandsReviewed-on: #4
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
let _settingsPromise = null
|
|
let _settings = null
|
|
let _requestGen = 0
|
|
|
|
export function getSettingsCached() { return _settings }
|
|
|
|
export async function getSettings(force = false) {
|
|
if (force) { _settings = null; _settingsPromise = null; _requestGen++ }
|
|
if (_settings) return _settings
|
|
if (_settingsPromise) return _settingsPromise
|
|
const gen = _requestGen
|
|
const stale = () => getSettings() // superseded by a force reset: defer to the fresh state
|
|
_settingsPromise = fetch('/auth/api/settings')
|
|
.then(r => (r.ok ? r.json() : {}))
|
|
.then(obj => gen === _requestGen ? (_settings = obj || {}) : stale())
|
|
.catch(() => gen === _requestGen ? (_settings = {}) : stale())
|
|
return _settingsPromise
|
|
}
|
|
|
|
export function uiBasePath() {
|
|
const base = _settings?.ui_base_path || '/auth/'
|
|
if (base === '/') return '/'
|
|
return base.endsWith('/') ? base : base + '/'
|
|
}
|
|
|
|
export function adminUiPath() { return uiBasePath() === '/' ? '/admin/' : uiBasePath() + 'admin/' }
|
|
|
|
export function makeUiHref(suffix = '') {
|
|
const trimmed = suffix.startsWith('/') ? suffix.slice(1) : suffix
|
|
if (!trimmed) return uiBasePath()
|
|
if (uiBasePath() === '/') return '/' + trimmed
|
|
return uiBasePath() + trimmed
|
|
} |