Skip to content

Add a dev sign-in provider so a local checkout needs no OAuth application - #14

Open
jankarres wants to merge 1 commit into
shellular-org:mainfrom
jankarres:jan/dev-sign-in-provider
Open

Add a dev sign-in provider so a local checkout needs no OAuth application#14
jankarres wants to merge 1 commit into
shellular-org:mainfrom
jankarres:jan/dev-sign-in-provider

Conversation

@jankarres

Copy link
Copy Markdown

A fresh checkout cannot be signed into at all: every provider needs credentials from Google, GitHub or Apple, so /auth/providers returns three disabled entries and onboarding, pairing and the app WebSocket stay out of reach. This adds a dev provider, switched on with DEV_AUTH_EMAIL, that signs you in as that address without contacting anyone. Closes #13.

Making it a provider rather than a side door is what keeps it to about 50 lines: the authorization URL is the server's own callback, so the state, the exchange code, the cookies and the deep link are all paths you already have, and the account comes out of upsertUserFromProvider like any other.

Keeping it out of production

Two gates, neither reachable through .env alone. NODE_ENV must be dev, which central:start hardcodes and the schema defaults to prod without, and DEV_AUTH_EMAIL must be set. While disabled the provider is filtered out of /auth/providers, so a production response is byte-identical to today's. I checked rather than assumed: a prod-mode instance with DEV_AUTH_EMAIL still in the same .env returned exactly the three original entries, and POST /auth/oauth/dev/start was refused while the same call against the dev instance succeeded.

The obvious objection deserves a plain answer. NODE_ENV=dev already fabricates a host for any id, skips host verification, echoes any CORS origin and bypasses the trusted-web-origin check, so an instance in that mode was never safe to expose. This joins that surface rather than widening it, and a third explicit flag is easy if you would rather have one.

Testing

pnpm type-check and biome check central/ clean. Against a local central and relay, dev appears in /auth/providers with the address set and is absent without, the callback sets the cookies, and the app reaches onboarding; from there I paired a real CLI host over the relay and browsed its filesystem as the signed-in dev user.

Before you merge

The app has no label or icon for a dev provider, so against a dev server its login screen renders that button with no caption. Cosmetic and only visible locally, but if you would rather the client stayed untouched I can expose the flow as an endpoint only. Same for anything else here: tell me and I will take care of it.

A fresh checkout cannot be signed into. Every provider needs credentials from
Google, GitHub or Apple, so `GET /auth/providers` returns three disabled
entries and the app stops at its login gate. Running the stack end to end is
therefore gated on registering an OAuth application, which is a lot of setup
for someone who only wants to see their change work.

Set DEV_AUTH_EMAIL and a fourth provider, `dev`, appears. Choosing it signs
you in as that address: nothing external is contacted, the authorization URL
is the server's own callback, and everything after the callback (single-use
state, exchange codes, browser cookies, deep links) is the same code path the
real providers take. The account is upserted by email like any other.

Two independent gates keep it out of production. It is enabled only when
NODE_ENV is `dev`, which `central:start` hardcodes to `prod`, and only when
DEV_AUTH_EMAIL is set. While disabled it is filtered out of
`GET /auth/providers` entirely, so a production response is byte-identical to
what it was before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local development sign-in without a Google, GitHub or Apple OAuth app

1 participant