diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-06-19 00:10:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-18 16:10:44 +0000 |
commit | a5d0246fff8e95ed750d44b8a2d1c633e0fc9ef3 (patch) | |
tree | 0872e28ff068854394393b9b324689bf7811a319 /modules/setting/oauth2.go | |
parent | 695f5d170bc60909a50d8a16047b1df3e3c1016d (diff) | |
download | gitea-a5d0246fff8e95ed750d44b8a2d1c633e0fc9ef3.tar.gz gitea-a5d0246fff8e95ed750d44b8a2d1c633e0fc9ef3.zip |
Avoid polluting the config (#25345)
Caught by #25330
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules/setting/oauth2.go')
-rw-r--r-- | modules/setting/oauth2.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go index 4dab468c10..836a2bb25f 100644 --- a/modules/setting/oauth2.go +++ b/modules/setting/oauth2.go @@ -120,18 +120,20 @@ func loadOAuth2From(rootCfg ConfigProvider) { OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile) } - key := make([]byte, 32) - n, err := base64.RawURLEncoding.Decode(key, []byte(OAuth2.JWTSecretBase64)) - if err != nil || n != 32 { - key, err = generate.NewJwtSecret() - if err != nil { - log.Fatal("error generating JWT secret: %v", err) - } - - secretBase64 := base64.RawURLEncoding.EncodeToString(key) - rootCfg.Section("oauth2").Key("JWT_SECRET").SetValue(secretBase64) - if err := rootCfg.Save(); err != nil { - log.Fatal("save oauth2.JWT_SECRET failed: %v", err) + if InstallLock { + key := make([]byte, 32) + n, err := base64.RawURLEncoding.Decode(key, []byte(OAuth2.JWTSecretBase64)) + if err != nil || n != 32 { + key, err = generate.NewJwtSecret() + if err != nil { + log.Fatal("error generating JWT secret: %v", err) + } + + secretBase64 := base64.RawURLEncoding.EncodeToString(key) + rootCfg.Section("oauth2").Key("JWT_SECRET").SetValue(secretBase64) + if err := rootCfg.Save(); err != nil { + log.Fatal("save oauth2.JWT_SECRET failed: %v", err) + } } } } |