~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

The console signs people in with atproto-client's OAuth client

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:client/oauth2

What changes

Sign-in through the crate. Signing in to the console, signing up at SIGNUP_PDS, and signing in to an account to move here go through atproto_client::oauth (atproto-client 0.4.0). console_login::clients builds two clients under the one client id and key (private_key_jwt, kid console). One signs people in. It keeps sessions in memory and revokes each one straight after its callback. The other signs in to accounts being moved here and keeps their sessions in the database (account_move::Moves). Each has its own callback, /console/callback and the new /console/move/callback. They are kept apart because the crate's callback ends any session its client already keeps for the same DID: with one shared client, signing in to the console as an account would end that account's move.

Stores. A migration drops console_login and replaces it with console_request, the crate's Pending kept whole by its state, which both clients share (console_login::Requests). account_move keeps only mover → DID → started. Its session lives in move_session, by account. What the sign-in carries (back, the browser's cookie secret, and mover) travels in the request's app_state. Before the code is redeemed, the callback reads the waiting request by its state and refuses it unless the browser holds the matching cookie, the request was made for this callback, and, for a move, the mover is still the one signed in.

Account move. Its own DPoP loop is gone. Calls go through client.pds(&session) with client.auth, and service_auth::token asks for the createAccount token. The session is refreshed when it is about to lapse, and once more when the server answers 401 to a lapsed token. NoRefresh and invalid_grant answer SignInAgain. Answers are capped with Xrpc::at_most: ANSWER_AT_MOST for JSON, REPO_AT_MOST for repos and files. Signing in to move another account gives back the one before. Another person's move of the same account is replaced.

Metadata. The client metadata comes from atproto::oauth::WebClient::metadata, the full confidential web client profile, with both redirects. Where CONSOLE_URL is not https at a public name it answers 500 and says why.

Telemetry. The host's Guarded client now sends through observe::Calls, so every guarded call is logged as a call line with a traceparent. That covers the proxy, notify, syncers, client metadata and a group's domain. The changes for 0.4's Asking/SendError are in authority, group_domain and oauth_clients.

Deleted. console_post, sign_in_at, authorization_server, signed_up, Pending, console_key's inline client assertions, the move's Move row (issuer, endpoints, key, tokens), renew, the hand-written as_moving DPoP/nonce loop, challenged, and the console_login table.

Why

The host had its own copy of the confidential OAuth client. The crate's copy checks more than it did: the server metadata against the full profile, the authorization server read again from the DID at the callback and before each refresh, and revoking a grant it refused. It is the same client the other apps use.

Behaviour changes, in the change file and docs/design/signing-in.md:

  • An authorization server must meet atproto's profile. It must require PAR, take client metadata documents, send iss (a callback without iss is refused, as before), and list the required methods.
  • The account's server is read again from its DID at the callback and before each refresh of a move.
  • A sign-in refused after its code was redeemed has its grant revoked. What is given back is the refresh token, not the access token.
  • The client metadata has the full profile and a second redirect. It answers 500 for a console not at https on a public name.
  • A move under way when the host upgrades is let go: the person signs in to the account again.
  • A typed https://… URL in place of a handle signs in whoever logs in at that server, as the crate's authorize takes it.
  • Statuses: a sign-up PDS that cannot be reached answers 502 (was 400). A token response whose sub is no DID answers 400 (was 403).

How it was checked

Clippy with warnings denied passes for the workspace. Run locally: console_login, account_move, domain, oauth_clients, proxy, authority, addresses and spaces. Both mock authorization servers now serve full profile metadata (tests/common/oauth::server_metadata) and resource metadata with resource. New tests:

  • a request left too long (UnknownState)
  • the store failing (500)
  • a refused login's grant revoked
  • the move's refresh refused, invalid_request and invalid_grant
  • signing in to move a second account
  • a database from before upgrading

common::rewind now remakes a dropped table with the columns later migrations added. The full gate and e2e are left to CI.

Shortcomings

  • The crate's authorize does not return the state, so the browser binding lives in app_state and the callback peeks at the request in the host's own store. The console client keeps its session in memory and revokes it straight after callback. atproto-client 0.5.0's authorize returning the state and callback_unkept would replace both, in a follow-up.
  • service_caller and the account-import token still use Resolver::with_key, not service_auth::verify_any. That is left for a follow-up.
  • No test sends an answer past the caps; at_most is tested in the crate.
Approved

This moves console sign-in, sign-up and the account-move sign-in onto atproto-client 0.4's OAuth client, with two clients under one client id and key. I read all 17 changed files and found nothing that has to change.

  • Browser binding. come_back reads the waiting request by its state without consuming it. It then requires three things before the crate redeems the code:

    • the request's redirect_uri equals this callback;
    • the browser's cookie matches the secret in app_state;
    • for a move, the mover is still the signed-in caller.

    A move request can't be completed at /console/callback, and a console request can't be completed at the move callback.

  • Move bookkeeping. keep_move replaces another person's move of the same account and returns the account this mover had before, so give_back revokes it. It skips the case where it is the same account. Swept and cancelled moves revoke through moving.revoke(did), which also drops the stored session.

  • Refresh handling. as_moving retries once after a refresh on a 401, and lapsed excludes use_dpop_nonce. NoRefresh and invalid_grant become SignInAgain. RepoNotFound still maps to None before the lapse check, and at_most replaces the old capped reads.

  • Migration, docs and change file. The migration drops the old tables and in-flight moves are let go, as the body says. The change file, signing-in.md, api.md and config.md match the behaviour changes the body lists.

  • Tests. They cover the new paths: expired request, store failure, revoked grant, refresh refused with each error, second-account move, and a pre-upgrade database.

When I read the checks, test, e2e, docs and check were still queued, so I could not see the coverage gate or the e2e result. Both gate the merge, so I'd wait for them.

One small thing, not worth blocking on: if keep_move fails after the crate has stored the session in move_session, the session is orphaned until the next sign-in to that account replaces it.

Approved

The only change since my approval is in console_login.rs. take_request and request now bind the connection guard to a local before the query. The SQL and results are the same, and the behaviour is unchanged. What I approved stands. As before, test, e2e and the coverage gate gate the merge, so wait for them.

Merged as 85acc8f