mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Member Settings gets Passkeys: add a passkey on this device under a name, see the account's passkeys and remove one. The sign-in page gets "Sign in with a passkey": the browser offers this WeKan's passkeys, no user name needed. Verification is @simplewebauthn/server 14.0.3 (MIT, pinned) against ROOT_URL's host and origin, so a passkey cannot sign in to another site or through another address; each sign-in signs a fresh challenge that is used once and expires in five minutes, and the signature counter must move forward, so a copied passkey is refused. A disabled account cannot sign in with one (the existing validateLoginAttempt hooks apply). Passkeys are a top-level user field, never published and not writable from the client; up to 20 per account. Not offered on Sandstorm. Member Settings also gets Log out everywhere: after a confirmation every login token of the account goes, so Meteor ends every session - other browsers, phones, the desktop app - and this one. Nothing else changes. models/lib/passkeys.js holds the relying party, base64url and the browser conversions; client/lib/passkeys.js uses navigator.credentials directly. tests/passkeys.test.cjs signs assertions with a software ES256 authenticator: a real signature verifies, and another key, another origin, another challenge or a counter that went back are refused; it also checks single-use challenges, the unpublished field and the pin. server/lib/tests/passkeys.tests.js runs in Meteor (2 passing): the module bundles, login options name no account, and registration needs a user. Documented in docs/Features/Login/Passkeys.md. The new strings are English placeholders until the next translation pass. Thanks to xet7 ! Fixes #5847.
34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
// #5847: passkeys in the browser (models/lib/passkeys.js converts; the
|
|
// server verifies, server/passkeys.js).
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Accounts } from 'meteor/accounts-base';
|
|
|
|
const { creationOptionsForBrowser, requestOptionsForBrowser, credentialToJSON } = require('/models/lib/passkeys');
|
|
|
|
export function passkeysSupported() {
|
|
return typeof window !== 'undefined' && !!window.PublicKeyCredential && !!navigator.credentials
|
|
&& !Meteor.settings?.public?.sandstorm;
|
|
}
|
|
|
|
// Makes a passkey on this device and saves it to the signed-in account.
|
|
export async function addPasskey(name) {
|
|
const { challengeId, options } = await Meteor.callAsync('passkeyRegistrationOptions');
|
|
const credential = await navigator.credentials.create({ publicKey: creationOptionsForBrowser(options) });
|
|
if (!credential) throw new Meteor.Error('passkey-cancelled');
|
|
return Meteor.callAsync('passkeyRegister', challengeId, credentialToJSON(credential), name || '');
|
|
}
|
|
|
|
// Signs in with a passkey the browser offers; resolves when signed in.
|
|
export async function signInWithPasskey() {
|
|
const { challengeId, options } = await Meteor.callAsync('passkeyLoginOptions');
|
|
const credential = await navigator.credentials.get({ publicKey: requestOptionsForBrowser(options) });
|
|
if (!credential) throw new Meteor.Error('passkey-cancelled');
|
|
const response = credentialToJSON(credential);
|
|
return new Promise((resolve, reject) => {
|
|
Accounts.callLoginMethod({
|
|
methodArguments: [{ passkey: { challengeId, response } }],
|
|
userCallback: error => (error ? reject(error) : resolve()),
|
|
});
|
|
});
|
|
}
|