feat(oidc): 支持自定义 OIDC 登录显示名称 (#6012)
* docs: add design spec for OIDC custom display name Mirrors the existing Custom OAuth Provider name pattern so admins can show a meaningful label instead of the hardcoded "OIDC" on the login page and in related copy. * feat(oidc): add configurable display name with OIDC fallback * feat(oidc): use configured display name in provider name and status API * feat(oidc): add display name field to default-theme OIDC settings Claude-Session: https://claude.ai/code/session_01FDkWJqigJi9yE3HG5pjZP5 * feat(oidc): show configured display name on default-theme login button * feat(oidc): add display name field to classic-theme OIDC settings * feat(oidc): show configured display name on classic-theme login button * fix(oidc): trim whitespace before applying display name fallback * chore: remove internal design doc from PR Design/planning docs are working artifacts for this session and shouldn't be submitted to the upstream project. * fix(oidc): lead with example in classic-theme display name placeholder Reorders the combined placeholder to show the example first, then the fallback note, matching the Custom OAuth Provider Name field's placeholder convention (example-only) that this feature mirrors. * fix(i18n): improve Russian grammar in OIDC display-name placeholder translation Leads each clause with its condition/subject and adds the missing verb, per PR review feedback. * test(web): remove redundant OIDC harness tests
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package system_setting
|
||||
|
||||
import "github.com/QuantumNous/new-api/setting/config"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/QuantumNous/new-api/setting/config"
|
||||
)
|
||||
|
||||
type OIDCSettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ClientId string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
WellKnown string `json:"well_known"`
|
||||
@@ -23,3 +28,14 @@ func init() {
|
||||
func GetOIDCSettings() *OIDCSettings {
|
||||
return &defaultOIDCSettings
|
||||
}
|
||||
|
||||
// GetEffectiveDisplayName returns the admin-configured display name, or the
|
||||
// literal "OIDC" when none has been set. Centralizing this fallback keeps the
|
||||
// default in one place for both the OAuth provider name and the public
|
||||
// status payload.
|
||||
func (s *OIDCSettings) GetEffectiveDisplayName() string {
|
||||
if trimmed := strings.TrimSpace(s.DisplayName); trimmed != "" {
|
||||
return trimmed
|
||||
}
|
||||
return "OIDC"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package system_setting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/setting/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOIDCSettings_GetEffectiveDisplayName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
displayName string
|
||||
want string
|
||||
}{
|
||||
{name: "blank falls back to OIDC", displayName: "", want: "OIDC"},
|
||||
{name: "custom name is returned verbatim", displayName: "Acme SSO", want: "Acme SSO"},
|
||||
{name: "whitespace-only falls back to OIDC", displayName: " ", want: "OIDC"},
|
||||
{name: "surrounding whitespace is trimmed", displayName: " Acme SSO ", want: "Acme SSO"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &OIDCSettings{DisplayName: tt.displayName}
|
||||
assert.Equal(t, tt.want, s.GetEffectiveDisplayName())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOIDCSettings_DisplayNamePersistenceRoundTrip(t *testing.T) {
|
||||
settings := &OIDCSettings{DisplayName: " Acme SSO "}
|
||||
manager := config.NewConfigManager()
|
||||
manager.Register("oidc", settings)
|
||||
|
||||
saved := make(map[string]string)
|
||||
require.NoError(t, manager.SaveToDB(func(key, value string) error {
|
||||
saved[key] = value
|
||||
return nil
|
||||
}))
|
||||
require.Equal(t, " Acme SSO ", saved["oidc.display_name"])
|
||||
|
||||
settings.DisplayName = ""
|
||||
require.NoError(t, manager.LoadFromDB(saved))
|
||||
assert.Equal(t, " Acme SSO ", settings.DisplayName)
|
||||
assert.Equal(t, "Acme SSO", settings.GetEffectiveDisplayName())
|
||||
}
|
||||
Reference in New Issue
Block a user