chadtmiller.com/group-host
atmosphere group host
0
0
# Reading a group
An app that reads a group on a group host, as an app such as Grain does.
First it reads what anyone may: the group's profile and how it's joined,
from its `meta` space, where the group lets anyone read it. Then it signs
in as the group, which an admin of the group approves in the host's
console, and reads what its members see: the profile again, its rules,
roles and members from its `members` space, and who asked to join from
the host's `org.atgrp.listJoinRequests`.
It is one file, `main.ts`, on atproto's own TypeScript packages, from the
spaces alpha the host runs against:
- `@atproto/oauth-client-node` signs in as the group: the loopback client
`http://localhost`, an app on this machine, with PKCE, DPoP and PAR.
- `@atproto/lex` calls the host's methods, typed by the schemas under
`lexicons/` at the top of this repository (`npm run lex` builds them).
- `@atproto/lex-space` reads the spaces. Signed out, the host gives a
credential for a space anyone may read. Signed in, the session asks the
host for a delegation token, which buys a credential for the space,
bound to a key of the app's. Each read is signed with that key and
checked against the MAC its server signs the answer with: the group's
own records at the host, each member's at their own PDS.
[Signing in](../../docs/design/signing-in.md),
[spaces](../../docs/design/spaces.md) and
[moderation](../../docs/design/moderation.md#labels) say what the host
does on its side.
## Running it
It needs Node at the version `.node-version` names, which runs `main.ts`
as it is.
```sh
cd examples/read-a-group
npm install
npm start <group handle or DID>
```
It prints what anyone sees of the group, and a link to the group's host.
Open it, sign in to the console as an admin of the group and approve the
app, and the browser comes back to the app, which prints what it read:
```
Anyone sees riders.groups.test:
A group to try things on: Seeded by atgrp group seed.
Joining: approval
Approve the app as an admin of riders.groups.test:
http://localhost:…/oauth/authorize?client_id=…
Signed in as did:plc:3jz7gt5zuk5ex7r7kyfrqumj, approved by did:plc:oakdsdmj447bfknob7fovr4t
Its members see:
A group to try things on: Seeded by atgrp group seed.
Joining: approval
Rules:
Be kind: Disagree with ideas, not people.
Stay on topic: Post what the group is for.
Members:
did:plc:oakdsdmj447bfknob7fovr4t Admin, Member
did:plc:rtsw4cryi3kfo6vjmt3tls53 Member (not confirmed)
Join requests: 1
did:plc:vudrq2h7weq5mrjrar5sqxxc Can I ride along on Sunday?
```
Then it gives its session back, so the group's apps don't list it.
What it does with what it reads:
- **Who approved.** The host names the member who approved beside the
tokens it answers with (`member`, a field of its own, which the OAuth
client doesn't keep, so the app reads it from the token answer as it
passes). The app takes the session only from an admin: a member whose
roles hold `include:org.atgrp.authManageAdmin`. Any other member who
approves it is told so, and the session is given back.
- **Confirmed members.** A membership is the group's record; the member
confirms it with an `org.atgrp.confirmation` in their own repo in the
members space, at their own PDS. One with no confirmation shows as not
confirmed.
- **Takedowns.** A member the group labels `!takedown` in the members
space, by a label of its own that hasn't lapsed, isn't shown.
- **Members-only groups.** Where only members may read the meta space, the
host answers anyone else `SpaceNotFound`, and the app says only members
see the profile.
A member whose roles may not admit anyone gets no `listJoinRequests`, and
the app says so. Approving with fewer roles narrows what the app gets, as
[what a token may do](../../docs/design/signing-in.md#what-a-token-may-do)
says.
### On `just dev`
`just dev` runs a host on a network of its own, with a PLC directory of
its own and the host on http. Name both, from what it prints:
```sh
PLC_URL=<the directory> HANDLE_RESOLVER=<the host> npm start riders.groups.localtest.me
```
and approve as `alice.test`, whose group Riders is. A PLC directory on
http tells the app it is on a test network, where it reaches hosts over
http too. `HANDLE_RESOLVER` has the host resolve the group's handle, which
it does for its own accounts.
## What it leaves out
- The space types `org.atgrp.meta` and `org.atgrp.members` are declared in
`main.ts` with `l.space(...)`, naming the collections it reads, rather
than generated: the alpha's `lex build` makes a space type of several
collections that TypeScript cannot type, so `npm run lex` leaves those
two out. Fixed upstream by
[bluesky-social/atproto#6085](https://github.com/bluesky-social/atproto/pull/6085).
- It reads the spaces as a sync service does (`SpaceReader`), every repo
with the credential. `SpaceClient` reads the signed-in account's own
repo with its session instead, which this host does not take yet.
- It keeps its session in memory, for one run. An app kept running keeps
it, refreshes it, and treats a refresh the host refuses as the group
disconnecting it.
- It isn't told of changes. A service syncing the group registers an
endpoint with each credential (`notifyRegistrationProvider`), which
serves `com.atproto.space.confirmRegistration` and `notifySpaceUpdate`,
at a public https address.
- It writes nothing. A write as the group is
`com.atproto.space.createRecord` and the like with the same session, for
a scope that writes (`space:org.atgrp.meta?collection=org.atgrp.about`),
as [checking each write](../../docs/design/signing-in.md#checking-each-write)
says.