Fix interactive login on SQL databases by widening the OpenIddict token type - #1329
Open
RTJoe wants to merge 1 commit into
Open
Fix interactive login on SQL databases by widening the OpenIddict token type#1329RTJoe wants to merge 1 commit into
RTJoe wants to merge 1 commit into
Conversation
OpenIddict 7.4 persists the full token type identifiers instead of the
short names used by earlier versions. The longest of them,
"urn:openiddict:params:oauth:token-type:authorization_code", needs 57
characters, but the token type column only allows 50, because the pinned
Squidex.OpenIdDict.EntityFramework fork still declares the old length.
Every interactive login therefore failed when the authorization code was
stored, and the user was redirected to the error page:
Msg 2628: String or binary data would be truncated in table
'OpenIddictTokens', column 'Type'.
The client credentials flow was unaffected, because the access token
identifier still fits into 50 characters. MongoDB was unaffected as
well, because it does not enforce a length.
Widen the column to 150 characters, which is the length official
OpenIddict uses for the same reason, and add a migration for all three
relational providers. The new test compares the stored value instead of
only saving it, because MySql truncates silently outside of strict mode.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Interactive logins fail on every SQL database. The user completes the external provider round trip and then lands on the error page:
The request fails while OpenIddict stores the authorization code:
with this inner exception:
Cause
OpenIddict.AspNetCoreis referenced at7.4.0, butSquidex.OpenIdDict.EntityFrameworkis pinned at7.2.1and still declaresHasMaxLength(50)for the token type. OpenIddict 7.4 persists the full token type identifiers rather than the short names it used before, andurn:openiddict:params:oauth:token-type:authorization_codeneeds 57 characters.Official OpenIddict widened this column to 150 characters for the same reason, so the mismatch only exists because the fork has no 7.4 release.
This is visible in the stored data — the token types changed shape mid-flight, and no authorization code has been written since:
access_tokenurn:ietf:params:oauth:token-type:access_tokenauthorization_codeTwo things masked the severity:
Fix
AppDbContext, matching official OpenIddict. This lives in Squidex rather than waiting for a 7.4 release of the fork.WidenOpenIddictTokenTypemigration for SQL Server, PostgreSQL and MySQL.EFOpenIddictTestswith a round trip over the realTokenTypeIdentifiers.Private.AuthorizationCodeconstant. The existing test passed because it used the legacy short"authorization_code"literal, so it never exercised the length.The new test asserts the value read back from the database rather than only that
SaveChangesAsyncsucceeded, because MySQL truncates silently outside strict mode, which would corrupt the token type instead of failing loudly.Verification
Reproduced and confirmed against a production SQL Server instance running
dev-8637: inserting a token with the authorization code identifier fails with the error above, while an access token insert succeeds. After widening the column to 150 the authorization code insert succeeds and interactive login works again.Note that the migration only repairs the schema. Existing deployments already broken by this need the migration to run, or the equivalent
ALTER TABLE.Automated tests were not run locally, as
Squidex.Data.Testsrequires Docker for its test containers.🤖 Generated with Claude Code