Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
8e1a7bdf
Commit
8e1a7bdf
authored
Mar 14, 2026
by
Glorhop
Browse files
fix: fixed an issue where OIDC login consistently used a synthetic email address
parent
02a66a01
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/handler/auth_oidc_oauth.go
View file @
8e1a7bdf
...
...
@@ -306,7 +306,7 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
}
identityKey
:=
oidcIdentityKey
(
issuer
,
subject
)
email
:=
oidcS
yntheticEmailFromIdentityKey
(
identityKey
)
email
:=
oidcS
electLoginEmail
(
userInfoClaims
.
Email
,
idClaims
.
Email
,
identityKey
)
username
:=
firstNonEmpty
(
userInfoClaims
.
Username
,
idClaims
.
PreferredUsername
,
...
...
@@ -831,6 +831,14 @@ func oidcSyntheticEmailFromIdentityKey(identityKey string) string {
return
"oidc-"
+
hex
.
EncodeToString
(
sum
[
:
16
])
+
service
.
OIDCConnectSyntheticEmailDomain
}
func
oidcSelectLoginEmail
(
userInfoEmail
,
idTokenEmail
,
identityKey
string
)
string
{
email
:=
strings
.
TrimSpace
(
firstNonEmpty
(
userInfoEmail
,
idTokenEmail
))
if
email
!=
""
{
return
email
}
return
oidcSyntheticEmailFromIdentityKey
(
identityKey
)
}
func
oidcFallbackUsername
(
subject
string
)
string
{
subject
=
strings
.
TrimSpace
(
subject
)
if
subject
==
""
{
...
...
backend/internal/handler/auth_oidc_oauth_test.go
View file @
8e1a7bdf
...
...
@@ -30,6 +30,20 @@ func TestOIDCSyntheticEmailStableAndDistinct(t *testing.T) {
require
.
Contains
(
t
,
e1
,
"@oidc-connect.invalid"
)
}
func
TestOIDCSelectLoginEmailPrefersRealEmail
(
t
*
testing
.
T
)
{
identityKey
:=
oidcIdentityKey
(
"https://issuer.example.com"
,
"subject-a"
)
email
:=
oidcSelectLoginEmail
(
"user@example.com"
,
"idtoken@example.com"
,
identityKey
)
require
.
Equal
(
t
,
"user@example.com"
,
email
)
email
=
oidcSelectLoginEmail
(
""
,
"idtoken@example.com"
,
identityKey
)
require
.
Equal
(
t
,
"idtoken@example.com"
,
email
)
email
=
oidcSelectLoginEmail
(
""
,
""
,
identityKey
)
require
.
Contains
(
t
,
email
,
"@oidc-connect.invalid"
)
require
.
Equal
(
t
,
oidcSyntheticEmailFromIdentityKey
(
identityKey
),
email
)
}
func
TestBuildOIDCAuthorizeURLIncludesNonceAndPKCE
(
t
*
testing
.
T
)
{
cfg
:=
config
.
OIDCConnectConfig
{
AuthorizeURL
:
"https://issuer.example.com/auth"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment