A major refactoring for more consistent and stricter flows.
- Force using the dedicated authentication site configured via auth-host - Stricter host validation - Using the restricted app consistently for all access control (instead of the old loginview).
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
import { startRegistration, startAuthentication } from '@simplewebauthn/browser'
|
||||
import aWebSocket from '@/utils/awaitable-websocket'
|
||||
import { getSettings } from '@/utils/settings'
|
||||
|
||||
// Generic path normalizer: if an auth_host is configured and differs from current
|
||||
// host, return absolute URL (scheme derived by aWebSocket). Otherwise, keep as-is.
|
||||
async function makeUrl(path) {
|
||||
const s = await getSettings()
|
||||
const h = s?.auth_host
|
||||
return h && location.host !== h ? `//${h}${path}` : path
|
||||
}
|
||||
|
||||
export async function register(resetToken = null, displayName = null) {
|
||||
let params = []
|
||||
if (resetToken) params.push(`reset=${encodeURIComponent(resetToken)}`)
|
||||
if (displayName) params.push(`name=${encodeURIComponent(displayName)}`)
|
||||
const qs = params.length ? `?${params.join('&')}` : ''
|
||||
const url = `/auth/ws/register${qs}`
|
||||
const ws = await aWebSocket(url)
|
||||
const ws = await aWebSocket(await makeUrl(`/auth/ws/register${qs}`))
|
||||
try {
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const registrationResponse = await startRegistration({ optionsJSON })
|
||||
@@ -23,7 +31,7 @@ export async function register(resetToken = null, displayName = null) {
|
||||
}
|
||||
|
||||
export async function authenticate() {
|
||||
const ws = await aWebSocket('/auth/ws/authenticate')
|
||||
const ws = await aWebSocket(await makeUrl('/auth/ws/authenticate'))
|
||||
try {
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const authResponse = await startAuthentication({ optionsJSON })
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
let _settingsPromise = null
|
||||
let _settings = null
|
||||
|
||||
export function getSettingsCached() { return _settings }
|
||||
|
||||
export async function getSettings() {
|
||||
if (_settings) return _settings
|
||||
if (_settingsPromise) return _settingsPromise
|
||||
_settingsPromise = fetch('/auth/api/settings')
|
||||
.then(r => (r.ok ? r.json() : {}))
|
||||
.then(obj => { _settings = obj || {}; return _settings })
|
||||
.catch(() => { _settings = {}; return _settings })
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user