feat(base): signing in with SimpleLogin through the register (ADR 0020, step 2)

The `simpleLogin` endpoint on halkyon_oidc's SimpleLogin preset: `begin`
for the app and platform (the state's marker for the forwarding page), at
most 30 an hour per network; `complete` with SimpleLogin's code, signed out
a session for the account with that SimpleLogin ID, signed in SimpleLogin
added to the caller's account, who becomes identified and anonymous no
longer. Someone new gets no account yet: their identity waits 30 minutes
under the attempt's ID (D16), with a handle suggested from their name,
`anna_mueller` (D17), for the sign-up of step 3.

The register alone holds the instance's SimpleLogin app
(`simpleLoginClientId`, `simpleLoginClientSecret`) and exchanges codes; a
member asks it for both steps and issues its own session. `SIGN_IN_WAYS`
says which ways the register offers, the instance's basics and the ways
in carry `simpleLogin`, GitHub links nobody more where SimpleLogin is
offered, and Learn's and Todo's pruning forgets the unfinished sign-ins
hourly. No migration: the tables are halkyon_oidc's, already in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-23 21:03:15 +02:00
commit 42d06f7ee8
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -1,4 +1,5 @@
import 'package:halkyon_base_server/base.dart';
import 'package:halkyon_oidc_server/testing.dart';
import 'package:serverpod/serverpod.dart';
import 'package:serverpod_auth_idp_server/core.dart';
@ -17,13 +18,14 @@ const testUpstreamSourceCodeUrl = 'https://code.example.org/halkyon_test';
const testMinimumAppBuild = 7;
/// Sets the module up on the pod [sessionBuilder]'s sessions run on, as a
/// host does before its pod starts, with [deletePersonData] as its
/// deletions and [profilePageNote] at the foot of profile pages, and
/// host does before its pod starts, for [app], with [deletePersonData] as
/// its deletions and [profilePageNote] at the foot of profile pages, and
/// authentication exactly as hosts run it
/// (`auth_config.dart`). Not on `Serverpod.instance`: that is the pod made
/// last, and a test file with several `withServerpod` groups has a pod each.
void useBase(
TestSessionBuilder sessionBuilder, {
String app = testApp,
List<PersonDataDeletion> deletePersonData = const [],
ProfilePageNote? profilePageNote,
AccountsMode accounts = const HoldsRegister(),
@ -32,7 +34,7 @@ void useBase(
HalkyonBase.configure(
pod,
HalkyonBase(
app: testApp,
app: app,
appName: testAppName,
upstreamSourceCodeUrl: testUpstreamSourceCodeUrl,
minimumAppBuild: testMinimumAppBuild,
@ -41,13 +43,38 @@ void useBase(
accounts: accounts,
),
);
// No password sign-in unless a test gives it keys, and no SimpleLogin
// unless a test gives it an app, whatever the test run's passwords and
// environment hold.
usePasswordKeys(pod, null);
useOfferedWays(pod, null);
useSimpleLoginApp(pod, null);
AuthServices.set(
tokenManagerBuilders: tokenManagerBuilders,
identityProviderBuilders: identityProviderBuilders(pod),
);
}
/// SimpleLogin on the pod [sessionBuilder]'s sessions run on (ADR 0020), the
/// instance's app answered by [fake] (none for null), and authentication set
/// up anew as hosts run it.
void useSimpleLogin(TestSessionBuilder sessionBuilder, FakeProvider? fake) {
final pod = sessionBuilder.build().serverpod;
useSimpleLoginApp(
pod,
fake == null
? null
: (
clientId: fake.clientId,
clientSecret: fake.clientSecret,
callbackUrl: fake.callbackUrl,
),
client: fake?.client,
);
AuthServices.set(
tokenManagerBuilders: tokenManagerBuilders,
identityProviderBuilders: identityProviderBuilders(pod),
);
// No password sign-in unless a test gives it keys, whatever the test
// run's passwords hold.
usePasswordKeys(pod, null);
}
/// Signs [person] in on a new device and returns the new session's id.