mirror of
https://github.com/bitbaum/accountkit.git
synced 2026-12-04 05:57:23 +01:00
* feat(auth): Lightning login (LNURL-auth, LUD-04), opt-in per deployment A free, Bitcoin-native way in: the person's own Lightning wallet signs a one-time challenge shown as a QR code (or opened through a lightning: link on the same device). No key, no third party, nothing paid. The signed key is a sign-in method (providerId "lightning"), never an email. - /lightning/start mints a challenge (five minutes, used once) and binds it to the asking browser with a signed cookie; /lightning/callback is the wallet's LUD-04 call and checks the DER secp256k1 signature of k1; /sign-in/lightning (polled) signs in or creates the person; /lightning/link adds a wallet to the signed-in person, never one that already signs in to someone else. - A second factor applies; minting and the wallet's call spend the credential bucket. - SignInForm and SignUpForm offer "Sign in with a Lightning wallet", AccountPanel "Add Lightning wallet"; words in all six languages. - Off until ACCOUNTKIT_LIGHTNING=1. Tests: LUD-01's own LNURL both ways, a signature made by OpenSSL, and the whole flow on a real database (PGlite) with a wallet that signs as LUD-04 says: sign-in and sign-in again, a forged signature, an onlooker without the browser's cookie, a second factor, linking and a taken wallet, and nothing mounted without the opt-in. Browser: QR, wallet link, 44px, no sideways scroll at 320 and 390px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9 * feat(screens): a product's own GitHub app on the shared screens Loki keeps its GitHub sign-in (its own app, githubSignIn: true). The shared screens drew only the shared sign-in and OrangeCat, so Loki could not move onto SignInForm without losing it. signInMethods takes githubSignIn and reports methods.github; SignInForm, SignUpForm and AccountPanel draw it beside OrangeCat. The variables alone still offer nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9 --------- Co-authored-by: Claude <noreply@anthropic.com>
84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { signInMethods } from "../dist/auth/methods.js";
|
|
import { SignInForm, SignUpForm } from "../dist/auth/react.js";
|
|
import { authLabelsFor } from "../dist/auth/translations.js";
|
|
|
|
const GITHUB = { GITHUB_CLIENT_ID: "app", GITHUB_CLIENT_SECRET: "secret" };
|
|
const client = { signIn: {}, signUp: {} };
|
|
|
|
test("a product's own GitHub app shows only when the product asked for it", () => {
|
|
assert.equal(
|
|
signInMethods(GITHUB, false).github,
|
|
false,
|
|
"the two variables alone offer nothing",
|
|
);
|
|
assert.equal(
|
|
signInMethods(GITHUB, false, { githubSignIn: true }).github,
|
|
true,
|
|
);
|
|
assert.equal(
|
|
signInMethods({}, false, { githubSignIn: true }).github,
|
|
false,
|
|
"both variables, or nothing",
|
|
);
|
|
});
|
|
|
|
test("the screens draw it beside OrangeCat, in the page's language", () => {
|
|
const methods = signInMethods(
|
|
{
|
|
...GITHUB,
|
|
ORANGECAT_OAUTH_CLIENT_ID: "a",
|
|
ORANGECAT_OAUTH_CLIENT_SECRET: "b",
|
|
},
|
|
false,
|
|
{ githubSignIn: true },
|
|
);
|
|
const words = (html) => html.replace(/<[^<>]*>/g, "\n");
|
|
const de = authLabelsFor("de");
|
|
const signIn = words(
|
|
renderToStaticMarkup(
|
|
createElement(SignInForm, {
|
|
client,
|
|
methods,
|
|
labels: de,
|
|
next: "/",
|
|
signInPath: "/de/sign-in",
|
|
signUpLink: null,
|
|
}),
|
|
),
|
|
);
|
|
assert.ok(
|
|
signIn.indexOf("Weiter mit OrangeCat") <
|
|
signIn.indexOf("Weiter mit GitHub"),
|
|
);
|
|
const signUp = words(
|
|
renderToStaticMarkup(
|
|
createElement(SignUpForm, {
|
|
client,
|
|
methods,
|
|
next: "/",
|
|
signUpPath: "/sign-up",
|
|
signInLink: null,
|
|
}),
|
|
),
|
|
);
|
|
assert.match(signUp, /Continue with GitHub/);
|
|
const without = renderToStaticMarkup(
|
|
createElement(SignInForm, {
|
|
client,
|
|
methods: signInMethods(GITHUB, false),
|
|
next: "/",
|
|
signInPath: "/sign-in",
|
|
signUpLink: null,
|
|
}),
|
|
);
|
|
assert.doesNotMatch(
|
|
without,
|
|
/GitHub/,
|
|
"no GitHub button without githubSignIn",
|
|
);
|
|
});
|