mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 16:46:37 +08:00
fix(oauth): 支持 Casdoor 认证,修复第三方回调的用户id为string时会导致服务器内部错误的问题 (#46)
* fix(oauth): support Casdoor string user IDs * test(oauth): verify legacy IDs and auth source isolation --------- Co-authored-by: Noru Wyrms <wyrmsnoru@gmail.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestOAuthUserInfoIgnoresProviderID verifies nonstandard IDs cannot affect OIDC identity parsing.
|
||||
func TestOAuthUserInfoIgnoresProviderID(t *testing.T) {
|
||||
for _, providerID := range []string{`"a27dfc56-07ae-4c9d-9e5c-99103bd8805f"`, `"88888"`, `88888`, `null`} {
|
||||
t.Run(providerID, func(t *testing.T) {
|
||||
payload := `{"id":` + providerID + `,"sub":"external-subject","preferred_username":"oidc-user","email":"oidc@example.com","name":"OIDC User"}`
|
||||
var info OAuthUserInfo
|
||||
if err := json.Unmarshal([]byte(payload), &info); err != nil {
|
||||
t.Fatalf("json.Unmarshal(OAuthUserInfo, id=%s) error = %v, want nil", providerID, err)
|
||||
}
|
||||
want := OAuthUserInfo{
|
||||
Sub: "external-subject",
|
||||
PreferredUsername: "oidc-user",
|
||||
Email: "oidc@example.com",
|
||||
Name: "OIDC User",
|
||||
}
|
||||
if info != want {
|
||||
t.Errorf("json.Unmarshal(OAuthUserInfo, id=%s) = %+v, want %+v", providerID, info, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user