Skip to content

fix: increase OAuth token column length to 4096#31

Closed
pctablet505 wants to merge 2 commits into
fastapi-users:mainfrom
pctablet505:fix-fastapi-users-1523-token-length
Closed

fix: increase OAuth token column length to 4096#31
pctablet505 wants to merge 2 commits into
fastapi-users:mainfrom
pctablet505:fix-fastapi-users-1523-token-length

Conversation

@pctablet505

@pctablet505 pctablet505 commented Jul 15, 2026

Copy link
Copy Markdown

Fixes fastapi-users/fastapi-users#1523

When an OAuth provider signs tokens with RS256, the resulting access and refresh tokens can easily exceed the 1024 characters we were allowing for access_token and refresh_token in SQLAlchemyBaseOAuthAccountTable. The reporter hit this with Authentik on PostgreSQL:

sqlalchemy.exc.DataError: (psycopg.errors.StringDataRightTruncation) value too long for type character varying(1024)

Another user confirmed the same failure on MariaDB:

sqlalchemy.exc.DataError: (asyncmy.errors.DataError) (1406, "Data too long for column 'access_token' at row 1")

In both cases the token cannot be persisted, so the login fails.

The fix increases both columns from String(length=1024) to String(length=4096), matching the length the reporter is already using as a workaround by overriding the column definitions in their own model. I also added a round-trip test that writes and reads back a 2048-character access token, so we don't accidentally truncate long tokens in the future.

Existing deployments will still need a manual Alembic migration (or equivalent) to widen already-created columns; SQLAlchemy won't resize them automatically.

@pctablet505

Copy link
Copy Markdown
Author

Closing this draft — PR #30 already covers the same fix, and the repo is in maintenance mode (discussion #1543).

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.

Access Token and Refresh Token field length too small

1 participant