fix: add retry fallback in registration and login for authenticators with unsupported PRF options
This commit is contained in:
@@ -87,7 +87,25 @@ export async function registerUser(username: string): Promise<RegistrationResult
|
|||||||
options.extensions.prf = {}
|
options.extensions.prf = {}
|
||||||
|
|
||||||
// 2. Start biometric Passkey creation
|
// 2. Start biometric Passkey creation
|
||||||
const credentialResponse = await startRegistration({ optionsJSON: options })
|
let credentialResponse
|
||||||
|
const prfRequested = !!options.extensions?.prf
|
||||||
|
try {
|
||||||
|
credentialResponse = await startRegistration({ optionsJSON: options })
|
||||||
|
} catch (err: any) {
|
||||||
|
const isOptionError = err.name === 'NotSupportedError' ||
|
||||||
|
err.message?.toLowerCase().includes('options') ||
|
||||||
|
err.message?.toLowerCase().includes('process') ||
|
||||||
|
err.message?.toLowerCase().includes('unable to')
|
||||||
|
if (prfRequested && isOptionError) {
|
||||||
|
console.warn('Registration with PRF extension failed, retrying without PRF:', err)
|
||||||
|
if (options.extensions) {
|
||||||
|
delete options.extensions.prf
|
||||||
|
}
|
||||||
|
credentialResponse = await startRegistration({ optionsJSON: options })
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Cryptographic Key derivation setup
|
// 3. Cryptographic Key derivation setup
|
||||||
const masterKey = generateMasterKey()
|
const masterKey = generateMasterKey()
|
||||||
@@ -204,7 +222,25 @@ export async function loginUser(username?: string): Promise<LoginResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Start biometric Passkey verification
|
// 2. Start biometric Passkey verification
|
||||||
const credentialResponse = await startAuthentication({ optionsJSON: options })
|
let credentialResponse
|
||||||
|
const prfRequested = !!options.extensions?.prf
|
||||||
|
try {
|
||||||
|
credentialResponse = await startAuthentication({ optionsJSON: options })
|
||||||
|
} catch (err: any) {
|
||||||
|
const isOptionError = err.name === 'NotSupportedError' ||
|
||||||
|
err.message?.toLowerCase().includes('options') ||
|
||||||
|
err.message?.toLowerCase().includes('process') ||
|
||||||
|
err.message?.toLowerCase().includes('unable to')
|
||||||
|
if (prfRequested && isOptionError) {
|
||||||
|
console.warn('Authentication with PRF extension failed, retrying without PRF:', err)
|
||||||
|
if (options.extensions) {
|
||||||
|
delete options.extensions.prf
|
||||||
|
}
|
||||||
|
credentialResponse = await startAuthentication({ optionsJSON: options })
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Verify assertion on the server
|
// 3. Verify assertion on the server
|
||||||
const verifyRes = await fetch(`${API_BASE}/login-verify`, {
|
const verifyRes = await fetch(`${API_BASE}/login-verify`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user