Skip to content

Fix OAuth token conflict - remove duplicate token creation#417

Merged
ngjunsiang merged 1 commit intoweeklyfrom
fix/oauth-token-conflict
Apr 7, 2026
Merged

Fix OAuth token conflict - remove duplicate token creation#417
ngjunsiang merged 1 commit intoweeklyfrom
fix/oauth-token-conflict

Conversation

@nycomp
Copy link
Copy Markdown
Contributor

@nycomp nycomp commented Apr 7, 2026

Summary

Fixes the OAuth sign-in flow that was creating duplicate campus tokens, causing PostgreSQL unique constraint violations.

Problem

The verify_login_and_redirect endpoint was creating campus tokens, and then the /token endpoint was also creating tokens. This resulted in duplicate token_id values, violating the PostgreSQL unique constraint.

Solution

  • Remove token creation from verify_login_and_redirect: This endpoint now ONLY creates authorization codes for apps to exchange
  • Fix /token endpoint to handle missing credentials: Previously, if credentials didn't exist, it would raise NotFoundError. Now it creates new credentials properly.

Changes

  • Removed resources.credentials[PROVIDER][user].new() call from verify_login_and_redirect
  • Added try/except in /token to handle NotFoundError when credentials don't exist
  • Token creation now happens ONLY in the /token endpoint

Testing

  1. Sign in to campus-profile as a new user
  2. Verify that token is created successfully
  3. Verify that subsequent sign-ins work correctly

Fixes #416

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

- Remove token creation from verify_login_and_redirect
- This endpoint should only create authorization codes
- /token endpoint is now the single source of truth for token creation
- Fixes PostgreSQL unique constraint violation on token_id

Fixes #416

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ngjunsiang ngjunsiang added the bug Something isn't working label Apr 7, 2026
@ngjunsiang ngjunsiang merged commit cf79cdf into weekly Apr 7, 2026
4 checks passed
@ngjunsiang ngjunsiang deleted the fix/oauth-token-conflict branch April 7, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth flow creates duplicate tokens causing PostgreSQL constraint violation

2 participants