An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Align OIDC client secret with API key settings https://github.com/siyuan-note/siyuan/issues/18542
Danielb0858cd42e1b
diff --git a/app/src/config/tabs/accessTab.ts b/app/src/config/tabs/accessTab.tsindex 672526ebca..f1c8cd6586 100644--- a/app/src/config/tabs/accessTab.ts+++ b/app/src/config/tabs/accessTab.ts@@ -88,7 +88,6 @@ const mountOIDCButton = (root: HTMLElement) => {root.querySelector("#oidcConfig")?.addEventListener("click", () => {const config = window.siyuan.config.oidc;const escape = (value: string) => Lute.EscapeHTMLStr(value);- const maskedClientSecret = "********";const dialog = new Dialog({title: window.siyuan.languages.oidcLogin,content: `<div class="b3-dialog__content" id="oidcConfigForm">@@ -117,7 +116,7 @@ const mountOIDCButton = (root: HTMLElement) => {<div class="config-name">${window.siyuan.languages.oidcClientSecret}</div><div class="fn__hr"></div><div class="b3-form__icona fn__block">- <input id="oidcClientSecret" data-field="clientSecret" type="password" class="b3-text-field b3-form__icona-input" spellcheck="false" autocomplete="off" value="${config.clientSecretConfigured ? maskedClientSecret : ""}">+ <input id="oidcClientSecret" data-field="clientSecret" type="password" class="b3-text-field b3-form__icona-input" spellcheck="false" autocomplete="off" value="${escape(config.clientSecret)}"><svg class="b3-form__icona-icon" data-action="togglePassword"><use xlink:href="#iconEye"></use></svg></div></div>@@ -152,7 +151,6 @@ const mountOIDCButton = (root: HTMLElement) => {const buttons = dialog.element.querySelectorAll<HTMLButtonElement>(".b3-dialog__action .b3-button");const clientSecretInput = form.querySelector<HTMLInputElement>('[data-field="clientSecret"]');bindPasswordIconaToggle(form, "oidcClientSecret");- let clientSecretEdited = false;let validationPollTimer = 0;let validationWindow: Window | null = null;let validationCancelled = false;@@ -170,16 +168,6 @@ const mountOIDCButton = (root: HTMLElement) => {form.querySelector<HTMLSelectElement>('[data-field="provider"]').addEventListener("change", refreshSections);form.querySelector<HTMLInputElement>('[data-field="enabled"]').addEventListener("change", refreshSections);form.querySelector<HTMLInputElement>('[data-field="allowAll"]').addEventListener("change", refreshSections);- const selectMaskedClientSecret = () => {- if (config.clientSecretConfigured && !clientSecretEdited) {- clientSecretInput.select();- }- };- clientSecretInput.addEventListener("focus", selectMaskedClientSecret);- clientSecretInput.addEventListener("click", selectMaskedClientSecret);- clientSecretInput.addEventListener("input", () => {- clientSecretEdited = true;- });refreshSections();const stopValidation = () => {window.clearInterval(validationPollTimer);@@ -239,15 +227,12 @@ const mountOIDCButton = (root: HTMLElement) => {try {const field = <T extends HTMLElement>(name: string) => form.querySelector<T>(`[data-field="${name}"]`);const claimRules = JSON.parse(field<HTMLTextAreaElement>("claimRules").value) as Config.IOIDCClaimRule[];- const initialClientSecret = config.clientSecretConfigured ? maskedClientSecret : "";- const clientSecretChanged = clientSecretEdited || clientSecretInput.value !== initialClientSecret;const nextConfig: Config.IOIDC = {enabled: field<HTMLInputElement>("enabled").checked,provider: field<HTMLSelectElement>("provider").value as Config.IOIDC["provider"],issuerURL: field<HTMLInputElement>("issuerURL").value,clientID: field<HTMLInputElement>("clientID").value,- clientSecret: clientSecretChanged ? clientSecretInput.value : "",- clientSecretConfigured: clientSecretChanged ? Boolean(clientSecretInput.value) : config.clientSecretConfigured,+ clientSecret: clientSecretInput.value,scopes: field<HTMLInputElement>("scopes").value.split(/[ ,]+/).filter(Boolean),redirectURL: field<HTMLInputElement>("redirectURL").value,allowAll: field<HTMLInputElement>("allowAll").checked,diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex 6bc92b3dcc..1c6d6fcbb3 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -127,7 +127,6 @@ declare namespace Config {issuerURL: string;clientID: string;clientSecret: string;- clientSecretConfigured: boolean;scopes: string[];redirectURL: string;allowAll: boolean;diff --git a/kernel/api/system.go b/kernel/api/system.goindex 8f92b67723..be34a6eef9 100644--- a/kernel/api/system.go+++ b/kernel/api/system.go@@ -904,9 +904,6 @@ func setOIDC(c *gin.Context) {return}currentConfig := model.Conf.GetOIDC()- if config.ClientSecret == "" && config.ClientSecretConfigured {- config.ClientSecret = currentConfig.ClientSecret- }config.Normalize()requireRemoteAuthentication := util.ContainerDocker == util.Container || !model.IsLocalRequest(c)if err := model.ValidateOIDCConfigurationChange(c.Request.Context(), config, requireRemoteAuthentication,diff --git a/kernel/conf/oidc.go b/kernel/conf/oidc.goindex 2d38558f6b..a6a0881c5f 100644--- a/kernel/conf/oidc.go+++ b/kernel/conf/oidc.go@@ -27,16 +27,15 @@ const (// OIDC 保存工作空间的 OpenID Connect 登录配置。type OIDC struct {- Enabled bool `json:"enabled"`- Provider string `json:"provider"`- IssuerURL string `json:"issuerURL"`- ClientID string `json:"clientID"`- ClientSecret string `json:"clientSecret"`- ClientSecretConfigured bool `json:"clientSecretConfigured"`- Scopes []string `json:"scopes"`- RedirectURL string `json:"redirectURL"`- AllowAll bool `json:"allowAll"`- ClaimRules []*OIDCClaimRule `json:"claimRules"`+ Enabled bool `json:"enabled"`+ Provider string `json:"provider"`+ IssuerURL string `json:"issuerURL"`+ ClientID string `json:"clientID"`+ ClientSecret string `json:"clientSecret"`+ Scopes []string `json:"scopes"`+ RedirectURL string `json:"redirectURL"`+ AllowAll bool `json:"allowAll"`+ ClaimRules []*OIDCClaimRule `json:"claimRules"`}// OIDCClaimRule 描述一条身份声明准入规则。同一规则的 Values 为或关系,不同规则之间为与关系。@@ -61,9 +60,6 @@ func (o *OIDC) Normalize() {o.Provider = strings.ToLower(strings.TrimSpace(o.Provider))o.IssuerURL = strings.TrimSpace(o.IssuerURL)o.ClientID = strings.TrimSpace(o.ClientID)- if o.ClientSecret != "" {- o.ClientSecretConfigured = true- }o.RedirectURL = strings.TrimSpace(o.RedirectURL)if len(o.Scopes) == 0 {o.Scopes = []string{"openid", "profile", "email"}diff --git a/kernel/model/conf.go b/kernel/model/conf.goindex f76784c21a..c0d7113851 100644--- a/kernel/model/conf.go+++ b/kernel/model/conf.go@@ -1331,10 +1331,6 @@ func GetMaskedConf() (ret *AppConf, err error) {if "" != ret.AccessAuthCode {ret.AccessAuthCode = MaskedAccessAuthCode}- if ret.OIDC != nil {- ret.OIDC.ClientSecretConfigured = ret.OIDC.ClientSecret != ""- ret.OIDC.ClientSecret = ""- }return}diff --git a/kernel/model/conf_secret_test.go b/kernel/model/conf_secret_test.goindex 3ba2b749fa..6fc5f2f565 100644--- a/kernel/model/conf_secret_test.go+++ b/kernel/model/conf_secret_test.go@@ -24,7 +24,7 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func TestGetMaskedConfHidesCookieKey(t *testing.T) {+func TestGetMaskedConfHidesCookieKeyAndPreservesOIDCSecret(t *testing.T) {const cookieKey = "session-cookie-signing-key"originalConf := Conf@@ -46,8 +46,8 @@ func TestGetMaskedConfHidesCookieKey(t *testing.T) {if cookieKey != Conf.CookieKey {t.Fatalf("cookie key in the runtime configuration was changed: %q", Conf.CookieKey)}- if maskedConf.OIDC.ClientSecret != "" || !maskedConf.OIDC.ClientSecretConfigured {- t.Fatalf("OIDC client secret state was not safely represented: %#v", maskedConf.OIDC)+ if maskedConf.OIDC.ClientSecret != "oidc-client-secret" {+ t.Fatalf("OIDC client secret was not preserved: %#v", maskedConf.OIDC)}if Conf.OIDC.ClientSecret != "oidc-client-secret" {t.Fatalf("OIDC client secret in runtime configuration was changed: %q", Conf.OIDC.ClientSecret)diff --git a/kernel/model/oidc.go b/kernel/model/oidc.goindex 5b673cc189..884dc8e60b 100644--- a/kernel/model/oidc.go+++ b/kernel/model/oidc.go@@ -106,10 +106,6 @@ func OIDCValidateStart(c *gin.Context) {ret.Msg = oidcLanguage(369, "Invalid OIDC configuration")return}- currentConfig := Conf.GetOIDC()- if config.ClientSecret == "" && config.ClientSecretConfigured {- config.ClientSecret = currentConfig.ClientSecret- }config.Normalize()requireRemoteAuthentication := util.ContainerDocker == util.Container || !IsLocalRequest(c)if err := ValidateOIDCConfigurationChange(c.Request.Context(), config, requireRemoteAuthentication,