aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwackbyte <wackbyte@pm.me>2024-01-28 07:36:44 -0500
committerGitHub <noreply@github.com>2024-01-28 12:36:44 +0000
commitd9b3849454e04c1f498c12e29b8c19660cbae328 (patch)
tree3e0140a7bb21c87c6a8f07248e55ffc2ca9a82a0 /modules
parent61f8ca4906c4c51f9e7e9598417a9674556e670a (diff)
downloadgitea-d9b3849454e04c1f498c12e29b8c19660cbae328.tar.gz
gitea-d9b3849454e04c1f498c12e29b8c19660cbae328.zip
Fix inconsistent naming of OAuth 2.0 `ENABLE` setting (#28951)
Renames it to `ENABLED` to be consistent with other settings and deprecates it. I believe this change is necessary because other setting groups such as `attachment`, `cors`, `mailer`, etc. have an `ENABLED` setting, but `oauth2` is the only one with an `ENABLE` setting, which could cause confusion for users. This is no longer a breaking change because `ENABLE` has been set as deprecated and as an alias to `ENABLED`.
Diffstat (limited to 'modules')
-rw-r--r--modules/setting/oauth2.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go
index 10cadf03dd..0d15e91ef0 100644
--- a/modules/setting/oauth2.go
+++ b/modules/setting/oauth2.go
@@ -93,7 +93,7 @@ func parseScopes(sec ConfigSection, name string) []string {
}
var OAuth2 = struct {
- Enable bool
+ Enabled bool
AccessTokenExpirationTime int64
RefreshTokenExpirationTime int64
InvalidateRefreshTokens bool
@@ -103,7 +103,7 @@ var OAuth2 = struct {
MaxTokenLength int
DefaultApplications []string
}{
- Enable: true,
+ Enabled: true,
AccessTokenExpirationTime: 3600,
RefreshTokenExpirationTime: 730,
InvalidateRefreshTokens: false,
@@ -114,16 +114,23 @@ var OAuth2 = struct {
}
func loadOAuth2From(rootCfg ConfigProvider) {
- if err := rootCfg.Section("oauth2").MapTo(&OAuth2); err != nil {
- log.Fatal("Failed to OAuth2 settings: %v", err)
+ sec := rootCfg.Section("oauth2")
+ if err := sec.MapTo(&OAuth2); err != nil {
+ log.Fatal("Failed to map OAuth2 settings: %v", err)
return
}
- if !OAuth2.Enable {
+ // Handle the rename of ENABLE to ENABLED
+ deprecatedSetting(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0")
+ if sec.HasKey("ENABLE") && !sec.HasKey("ENABLED") {
+ OAuth2.Enabled = sec.Key("ENABLE").MustBool(OAuth2.Enabled)
+ }
+
+ if !OAuth2.Enabled {
return
}
- OAuth2.JWTSecretBase64 = loadSecret(rootCfg.Section("oauth2"), "JWT_SECRET_URI", "JWT_SECRET")
+ OAuth2.JWTSecretBase64 = loadSecret(sec, "JWT_SECRET_URI", "JWT_SECRET")
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)