mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
SQRL (https://www.grc.com/sqrl/sqrl.htm) signs in with a SQRL app or client instead of a password. A site admin turns it on in Admin Panel -> Settings, off by default; WeKan must be at an https:// ROOT_URL. A member adds their identity once in Member Settings -> SQRL, by scanning the QR code or opening their SQRL client; the sign-in page then offers Sign in with SQRL, shows the sqrl:// link and its QR code, and signs in by itself once the client has answered. With the client on the same computer (cps), the client opens WeKan with a one-time token instead. The protocol is GRC's SQRL Semantics: the client posts signed requests to /sqrl, each verified with Ed25519 by Node.js's own crypto, no new dependency for it. Every nut is random and used once, taken atomically; each request must carry the server's previous reply unchanged; a request from another address than the sign-in page's is refused unless the client says noiptest; disable needs the identity's signature, and enable, remove and rekeying need the rescue code's unlock key. An identity WeKan does not know can neither make an account nor sign in. The page learns of success by polling with a secret only it holds, and signing in uses that once. The identity's public keys are a user field never published and not writable from the client. Not offered on Sandstorm. sqrlonly and hardlock are not supported. The QR code is qrcode-generator 1.4.4 (MIT, pinned). models/lib/sqrl.js is the protocol with storage and signature check passed in; tests/sqrl.test.cjs drives it with a software SQRL client using real Ed25519 keys - adding an identity, the waiting page, cps, another network, forged signatures, replayed nuts, altered replies, unknown identities, another member's identity, disable/enable, rekey and remove - and pins the server's single-use and visibility rules and the UI. server/lib/tests/sqrl.tests.js runs in Meteor (2 passing): off by default, then an identity added and signed in with once, through the real /sqrl route and MongoDB. Documented in docs/Features/Login/SQRL.md. The new strings are English placeholders until the translations that follow. Thanks to xet7 ! Fixes #2460.
53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
// #2460: SQRL in the browser (the server side is server/sqrl.js). A session
|
|
// shows its sqrl:// link and QR code, then waits for the member's SQRL client
|
|
// to answer; the sign-in page then signs in with the session's secret.
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Accounts } from 'meteor/accounts-base';
|
|
import qrcode from 'qrcode-generator';
|
|
|
|
const POLL_MS = 2000;
|
|
|
|
export function sqrlOffered(setting) {
|
|
return !!(setting && setting.sqrlEnabled === true) && !Meteor.settings?.public?.sandstorm;
|
|
}
|
|
|
|
// The link as a QR code, for a SQRL app on a phone. The SVG is made from the
|
|
// link alone, which the server built.
|
|
export function sqrlQrSvg(link) {
|
|
const qr = qrcode(0, 'M');
|
|
qr.addData(link);
|
|
qr.make();
|
|
return qr.createSvgTag({ cellSize: 4, margin: 2, scalable: true });
|
|
}
|
|
|
|
function login(sqrl) {
|
|
return new Promise((resolve, reject) => {
|
|
Accounts.callLoginMethod({ methodArguments: [{ sqrl }], userCallback: error => (error ? reject(error) : resolve()) });
|
|
});
|
|
}
|
|
|
|
// Runs one session. `show({ link, svg })` is called once there is something
|
|
// to scan; resolves to how it ended: 'signed-in' (a sign-in session), 'done'
|
|
// (an identity was added), 'cps' (the SQRL client signed in another browser
|
|
// tab on this device), 'expired' or 'cancelled'.
|
|
export async function runSqrlSession(purpose, { show, cancelled }) {
|
|
const { session, secret, link } = await Meteor.callAsync('sqrlStart', purpose);
|
|
show({ link, svg: sqrlQrSvg(link) });
|
|
while (!cancelled()) {
|
|
await new Promise(resolve => setTimeout(resolve, POLL_MS));
|
|
if (cancelled()) break;
|
|
const state = await Meteor.callAsync('sqrlPoll', session, secret);
|
|
if (state === 'ready') {
|
|
await login({ session, secret });
|
|
return 'signed-in';
|
|
}
|
|
if (state !== 'pending') return state === 'used' ? 'expired' : state;
|
|
}
|
|
return 'cancelled';
|
|
}
|
|
|
|
// The page a SQRL client opened on this device (cps): /sign-in?sqrl=<token>.
|
|
export function signInWithSqrlToken(token) {
|
|
return login({ cps: String(token) });
|
|
}
|