ADR 0044's step 6a (D42, D43, D45): accounts for programs, such as AI assistants, that an identified person makes from the Profile. halkyon_base keeps them on the instance's register, which its members ask: an agent is an account (agent_account: its owner, its name, its public keys, set by itself once) with one token (agent_token: 32 random bytes, kept as their SHA-256 alone, shown once). agents.create, mine, newToken, revoke, delete and setKeys serve its owner; agentSignIn.signIn exchanges the token for an ordinary server-side session of a day, with the scopes identified and agent, at most 60 sign-ins an hour from a network. Revoking a token or making a new one ends the agent's sessions; a token unused for 90 days lapses in every service's pruning. Up to 5 agents a person, where the operator didn't switch them off (AGENTS=off; said on the privacy page and in instance.basics). An agent makes no agents, creates or owns no shared space, is invited and raised as a Viewer alone, is never handed a space on, is named no operator and granted no assistants; each refusal has its test. Deleting a person deletes their agents first; an agent's public profile names whose agent it is. In the apps, every Profile has an Agents card (halkyon_app's AgentsSection): made with a name and a handle, its token shown once to copy, a new token, the token taken back, deleted. Learn's Share sheet marks an agent among the members and offers it no role above Viewer. The migrations, the module's and each host's (Learn, Meditate, Todo, Train), are additive alone: CREATE TABLE "agent_account" with a unique index on "agentId" (one row an agent account) and one on "ownerId" (a person's agents, and deleting them with the person), and CREATE TABLE "agent_token" with unique indexes on "agentId" (one token an agent) and "tokenHash" (the sign-in finds the token by its hash). No existing table is touched, so the server before the deploy keeps working on the migrated database. Whats-New: Make agents in your Profile: accounts for programs such as AI assistants, which sign in with a token and see only what you share with them. Whats-New-De: Leg in deinem Profil Agenten an: Konten für Programme wie KI-Assistenten, die sich mit einem Token anmelden und nur sehen, was du mit ihnen teilst. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
167 lines
5.1 KiB
Dart
167 lines
5.1 KiB
Dart
import 'package:clock/clock.dart';
|
|
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';
|
|
|
|
import '../test_tools/serverpod_test_tools.dart';
|
|
|
|
/// The app the tests' host is.
|
|
const testAppName = 'Halkyon Test';
|
|
|
|
/// The id of the app the tests' host serves.
|
|
const testApp = 'test';
|
|
|
|
/// Where the tests' host says its project publishes its source.
|
|
const testUpstreamSourceCodeUrl = 'https://code.example.org/halkyon_test';
|
|
|
|
/// The oldest app build the tests' host works with.
|
|
const testMinimumAppBuild = 7;
|
|
|
|
/// Sets the module up on the pod [sessionBuilder]'s sessions run on, as a
|
|
/// host does before its pod starts, for [app], with [deletePersonData] as
|
|
/// its deletions, [profilePageNote] at the foot of profile pages and
|
|
/// [privacyPagePoints] on the privacy page, [files] as its file store, 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,
|
|
List<PrivacyPagePoint> privacyPagePoints = const [],
|
|
AccountsMode accounts = const HoldsRegister(),
|
|
FileStore? files,
|
|
SpaceGrants? spaces,
|
|
}) {
|
|
final pod = sessionBuilder.build().serverpod;
|
|
HalkyonBase.configure(
|
|
pod,
|
|
HalkyonBase(
|
|
app: app,
|
|
appName: testAppName,
|
|
upstreamSourceCodeUrl: testUpstreamSourceCodeUrl,
|
|
minimumAppBuild: testMinimumAppBuild,
|
|
deletePersonData: deletePersonData,
|
|
profilePageNote: profilePageNote,
|
|
privacyPagePoints: privacyPagePoints,
|
|
accounts: accounts,
|
|
files: files,
|
|
spaces: spaces,
|
|
),
|
|
);
|
|
// 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);
|
|
useAgents(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),
|
|
);
|
|
}
|
|
|
|
/// Signs [person] in on a new device and returns the new session's id.
|
|
Future<UuidValue> signInNewDevice(
|
|
Session session,
|
|
UuidValue person, {
|
|
Set<Scope> scopes = const {},
|
|
String method = 'test',
|
|
}) async {
|
|
Future<Set<UuidValue>> sessionIds() async => {
|
|
for (final serverSideSession in await ServerSideSession.db.find(
|
|
session,
|
|
where: (t) => t.authUserId.equals(person),
|
|
))
|
|
serverSideSession.id!,
|
|
};
|
|
|
|
final before = await sessionIds();
|
|
await AuthServices.instance.tokenManager.createToken(
|
|
session,
|
|
authUserId: person,
|
|
method: method,
|
|
scopes: scopes,
|
|
);
|
|
return (await sessionIds()).difference(before).single;
|
|
}
|
|
|
|
/// A person as codes by mail left them before passwords (ADR 0017):
|
|
/// identified, with [address] as their only way in, and no password; with
|
|
/// [handle] where given (ADR 0020, D5), their profile private.
|
|
Future<UuidValue> newPersonWithAddress(
|
|
Session session,
|
|
String address, {
|
|
String? handle,
|
|
}) async {
|
|
final person = (await AuthServices.instance.authUsers.create(
|
|
session,
|
|
scopes: {identified},
|
|
)).id;
|
|
// INSERT INTO "email_identity" ("authUserId", "addressHash", "createdAt")
|
|
// VALUES ($1, $2, $3)
|
|
await EmailIdentity.db.insertRow(
|
|
session,
|
|
EmailIdentity(
|
|
authUserId: person,
|
|
addressHash: addressHash(session.serverpod, address),
|
|
createdAt: clock.now(),
|
|
),
|
|
);
|
|
if (handle != null) {
|
|
// INSERT INTO "public_profile" (…) VALUES (…)
|
|
await PublicProfile.db.insertRow(
|
|
session,
|
|
PublicProfile(
|
|
authUserId: person,
|
|
handle: handle,
|
|
handleKey: handle.toLowerCase(),
|
|
displayName: '',
|
|
bio: '',
|
|
links: const [],
|
|
verifiedLinks: const [],
|
|
updatedAt: clock.now(),
|
|
),
|
|
);
|
|
}
|
|
return person;
|
|
}
|
|
|
|
/// An anonymous account, as apps made them on their first start until
|
|
/// ADR 0020, D25, left from before.
|
|
Future<UuidValue> newAnonymousPerson(
|
|
Session session, {
|
|
DateTime? createdAt,
|
|
}) async {
|
|
final person = (await AuthServices.instance.authUsers.create(session)).id;
|
|
await AnonymousAccount.db.insertRow(
|
|
session,
|
|
AnonymousAccount(authUserId: person, createdAt: createdAt),
|
|
);
|
|
return person;
|
|
}
|