Skip to content

A declared identity key matches a fresh sign-in to its existing connection - #305

Merged
czpython merged 2 commits into
mainfrom
commonzenpython/eng-870-service-declared-identity-key-for-connection-dedup-and
Aug 22, 2026
Merged

A declared identity key matches a fresh sign-in to its existing connection#305
czpython merged 2 commits into
mainfrom
commonzenpython/eng-870-service-declared-identity-key-for-connection-dedup-and

Conversation

@czpython

@czpython czpython commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Since #302, a fresh sign-in always creates a new connection. A user can hold two live connections for one provider account. A revoke and a new sign-in always change the connection id. The platform cannot know that two consents are the same account, unless the service tells it.

What changes

  • Service gets an opt-in identity_key classvar beside identity_endpoint. It names the identity fact that identifies the provider account: "sub" for Google, "id" for GitHub. One line per service. There is no cross-provider key list — a generic guess can attach a fresh consent to the wrong row, so Revoking a connection is a state the row keeps, not a deletion #302 deleted one.
  • With the key declared, the OAuth callback compares a fresh sign-in's identity with the owner's existing connections for the provider. On a match, the sign-in updates that row: a live row gets the new tokens, a revoked row becomes live again under its old id, and the callback evicts the cached access token. With no match, no key, or no key value in the identity facts, the callback creates a new connection as before.
  • A live row wins over revoked rows when both match. Among revoked rows, the latest consent wins.
  • The matched path publishes oauth.connected with reconsent=true. That is the flag's documented meaning: the consent replaced an existing connection's tokens.

A live match updates the row; it is not refused. The consent already happened, and a refusal would discard a completed grant. The update keeps the connection id stable.

No schema change: the lookup reads the existing identity JSONB. Documented beside identity_endpoint in writing-an-extension.md.

Verification

  • ruff check / ruff format --check: clean
  • New tests: a keyed match makes a revoked row live again; a live row gets the new tokens and loses its cached access token; a live match wins over a revoked match; a missing key value creates a new row. The existing new-row-per-sign-in tests pass unchanged.

🤖 Generated with Claude Code

…ction

A Service may name the identity fact that identifies the provider
account (identity_key = "sub"). Declared, a fresh sign-in whose
identity matches an existing connection for the same owner lands on
that row — a live row's tokens are replaced, a revoked row comes back
to life under its old id — instead of creating a sibling. A live match
outranks revoked history. Undeclared, every fresh sign-in stays a new
connection.
@czpython
czpython force-pushed the commonzenpython/eng-870-service-declared-identity-key-for-connection-dedup-and branch from ee1a935 to 19a6461 Compare August 22, 2026 09:44
@czpython
czpython merged commit a99eb3c into main Aug 22, 2026
1 check passed
@czpython
czpython deleted the commonzenpython/eng-870-service-declared-identity-key-for-connection-dedup-and branch August 22, 2026 09:47
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.

1 participant