aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting/oauth2.go
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2023-06-18 16:56:50 -0400
committerGitHub <noreply@github.com>2023-06-18 20:56:50 +0000
commite9fab3ea3eae00f4375f01faba5c6cff2b98bf4f (patch)
treec3bb35c7c82b64a11502f36cc9cc73429d8fa78c /modules/setting/oauth2.go
parente0bd6ebabdcfa45113beb0f3cc28362e62011716 (diff)
downloadgitea-e9fab3ea3eae00f4375f01faba5c6cff2b98bf4f.tar.gz
gitea-e9fab3ea3eae00f4375f01faba5c6cff2b98bf4f.zip
Avoid polluting the config (#25345) (#25354)
Backport #25345 by @wxiaoguang Caught by #25330 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/setting/oauth2.go')
-rw-r--r--modules/setting/oauth2.go26
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)
+ }
}
}
}