mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
OpenIDConnect Error handleOAuth2SignIn() [E] EnsureLinkExternalToUser: mssql nvarchar to datetime covnersion #14154
Closed
opened 2025-11-02 11:04:39 -06:00 by GiteaMirror
·
9 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v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4.0
v1.4.0-rc3
v1.4.0-rc2
v1.3.3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#14154
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Binomimus on GitHub (Feb 18, 2025).
Description
We tried setting up gitea with OAuth Authentication against Citrix NetScaler as IDP. Login seems to be fine and the user is asked to link that account or create a new one. Both is resulting in an 500 server error
The relevant logs shows a conversion error while writing something to the database (mssql message is in german, sorry for that):
"...web/auth/oauth.go:340:handleOAuth2SignIn() [E] EnsureLinkExternalToUser: mssql: Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs."
The mssql error translates to "When converting an nvarchar data type to a datetime data type, the value is out of range."
gitea configuration for authentication source: only client id, secret and discovery url are configured
netscaler configuration for idp: client id, secret, redirect url, issuer name (iss), audience (aud) are configured
When the user authenticates the gitea server is checking the userinfo from /oauth/idp/userinfo and receives this response:
{"iss": "https://oauth.company.de", "issued_to": "https://git.company.de/user/oauth2/companyOAUTH/callback", "aud": "#clientID#", "sub": "my.name@company.de", "expires_in": 3559, "iat": 1739888790, "exp": 1739889090, "name": "my name", "given_name": "my", "family_name": "name", "initials": "myn", "preferred_username": "my name", "unique_name": "mname", "upn": "my.name@company.de"}I assume this is not an issue with authentication but some user info which is not getting updated correctly. We have LDAP authentication in place so it must be something specific to OAuth. Maybe some value from the JWT should get updated to the database.
Any help is appreciated
Gitea Version
1.23.3
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
gitea runs in docker, see https://docs.gitea.com/installation/install-with-docker
Database
None
@wxiaoguang commented on GitHub (Feb 19, 2025):
The only "datetime" field for "external user" is
ExpiresAtc2e23d3301/models/user/external_login_user.go (L76)At
web/auth/oauth.go:340:handleOAuth2SignIn(), theEnsureLinkExternalToUsersetsExpiresAtbytoExternalLoginUserand try to update database.c2e23d3301/services/externalaccount/user.go (L75-L82)toExternalLoginUserjust uses the OAuth2 resultgothUserdirectly.So if you are able to add more logs and build your instance to debug, I think it need to figure out the content of "gothUser" first, I guess it's
ExpiresAtis not valid (just a guess).And you could enable the LOG_SQL config option to see all SQL statements to see which SQLs causes that error.
@Binomimus commented on GitHub (Feb 19, 2025):
Hi wxiaoguang,
thanks for checking on this. I've some more logs here and plan to investigate more later today
@wxiaoguang commented on GitHub (Feb 19, 2025):
It might also be a XORM bug due to
nvarcharvsdatetimetype @lunnySince the data in your log
expires_at='2025-02-19 12:29:40'seems right.@wxiaoguang commented on GitHub (Feb 19, 2025):
I made a quick test:
It seems working as expected on https://dbfiddle.uk/LF2O4lu6 .
Does it work on your MSSQL instance? What's the table structure of your
external_login_usertable and what if you try to insert intoexternal_login_usertable by the logged INSERT manually? If it could reproduce the problem, it could be easier to figure out why.@Binomimus commented on GitHub (Feb 19, 2025):
Hi wxiaoguang,
your test generates the same error within MSSQL. However, when i use an ISO8601 date format (with "T" instead of space), it will work:
MS SQL Server Infos:
@Binomimus commented on GitHub (Feb 19, 2025):
Hi wxiaoguang,
I found the difference. When changing the language to english it will work with space as well (either by changing the default language of the user or setting it beforehand in the query).
this will always work:
this will always fail:
this will always work as well:
@wxiaoguang commented on GitHub (Feb 19, 2025):
Hmm, it's really tricky. MSSQL has too many strange behaviors ....... could you fine-tune your MSSQL server to make it work with
N'2025-02-19 12:31:44'? Because IMO Gitea can't be a know-everything app to various database configurations.And IIRC, using space is the ANSI SQL standard
@Binomimus commented on GitHub (Feb 19, 2025):
Changing the default language of the gitea user within MSSQL fixed it.
Thank you very much for pointing me in the right direction.
I always thought ISO8601 was the most common format.
I can't tell whether it might be feasible to handle this in the code or just add language=english as a requirement in the documentation for mssql (at least I could not find any mention of it).
@Binomimus commented on GitHub (Feb 24, 2025):
Solution:
MSSQL user for gitea database should have set language to english to avoid conversion issues with the datetime string