Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 25329c2

Browse files
wackbyteHenry Goodman
authored and
Henry Goodman
committedJan 31, 2024
Fix inconsistent naming of OAuth 2.0 ENABLE setting (go-gitea#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`.
1 parent 07ad5d7 commit 25329c2

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed
 

‎custom/conf/app.example.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ INTERNAL_TOKEN=
524524
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525525
;;
526526
;; Enables OAuth2 provider
527-
ENABLE = true
527+
ENABLED = true
528528
;;
529529
;; Algorithm used to sign OAuth2 tokens. Valid values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, EdDSA
530530
;JWT_SIGNING_ALGORITHM = RS256

‎docs/content/administration/config-cheat-sheet.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ This section only does "set" config, a removed config key from this section won'
11071107

11081108
## OAuth2 (`oauth2`)
11091109

1110-
- `ENABLE`: **true**: Enables OAuth2 provider.
1110+
- `ENABLED`: **true**: Enables OAuth2 provider.
11111111
- `ACCESS_TOKEN_EXPIRATION_TIME`: **3600**: Lifetime of an OAuth2 access token in seconds
11121112
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
11131113
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used

‎docs/content/administration/config-cheat-sheet.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Gitea 创建以下非唯一队列:
10431043

10441044
## OAuth2 (`oauth2`)
10451045

1046-
- `ENABLE`: **true**:启用OAuth2提供者。
1046+
- `ENABLED`: **true**:启用OAuth2提供者。
10471047
- `ACCESS_TOKEN_EXPIRATION_TIME`**3600**:OAuth2访问令牌的生命周期,以秒为单位。
10481048
- `REFRESH_TOKEN_EXPIRATION_TIME`**730**:OAuth2刷新令牌的生命周期,以小时为单位。
10491049
- `INVALIDATE_REFRESH_TOKENS`**false**:检查刷新令牌是否已被使用。

‎modules/setting/oauth2.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func parseScopes(sec ConfigSection, name string) []string {
9393
}
9494

9595
var OAuth2 = struct {
96-
Enable bool
96+
Enabled bool
9797
AccessTokenExpirationTime int64
9898
RefreshTokenExpirationTime int64
9999
InvalidateRefreshTokens bool
@@ -103,7 +103,7 @@ var OAuth2 = struct {
103103
MaxTokenLength int
104104
DefaultApplications []string
105105
}{
106-
Enable: true,
106+
Enabled: true,
107107
AccessTokenExpirationTime: 3600,
108108
RefreshTokenExpirationTime: 730,
109109
InvalidateRefreshTokens: false,
@@ -114,16 +114,23 @@ var OAuth2 = struct {
114114
}
115115

116116
func loadOAuth2From(rootCfg ConfigProvider) {
117-
if err := rootCfg.Section("oauth2").MapTo(&OAuth2); err != nil {
118-
log.Fatal("Failed to OAuth2 settings: %v", err)
117+
sec := rootCfg.Section("oauth2")
118+
if err := sec.MapTo(&OAuth2); err != nil {
119+
log.Fatal("Failed to map OAuth2 settings: %v", err)
119120
return
120121
}
121122

122-
if !OAuth2.Enable {
123+
// Handle the rename of ENABLE to ENABLED
124+
deprecatedSetting(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0")
125+
if sec.HasKey("ENABLE") && !sec.HasKey("ENABLED") {
126+
OAuth2.Enabled = sec.Key("ENABLE").MustBool(OAuth2.Enabled)
127+
}
128+
129+
if !OAuth2.Enabled {
123130
return
124131
}
125132

126-
OAuth2.JWTSecretBase64 = loadSecret(rootCfg.Section("oauth2"), "JWT_SECRET_URI", "JWT_SECRET")
133+
OAuth2.JWTSecretBase64 = loadSecret(sec, "JWT_SECRET_URI", "JWT_SECRET")
127134

128135
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
129136
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)

‎routers/web/user/setting/applications.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func loadApplicationsData(ctx *context.Context) {
9595
return
9696
}
9797
ctx.Data["Tokens"] = tokens
98-
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
98+
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enabled
9999
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
100-
if setting.OAuth2.Enable {
100+
if setting.OAuth2.Enabled {
101101
ctx.Data["Applications"], err = db.Find[auth_model.OAuth2Application](ctx, auth_model.FindOAuth2ApplicationsOptions{
102102
OwnerID: ctx.Doer.ID,
103103
})

‎routers/web/web.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func registerRoutes(m *web.Route) {
304304
validation.AddBindingRules()
305305

306306
linkAccountEnabled := func(ctx *context.Context) {
307-
if !setting.Service.EnableOpenIDSignIn && !setting.Service.EnableOpenIDSignUp && !setting.OAuth2.Enable {
307+
if !setting.Service.EnableOpenIDSignIn && !setting.Service.EnableOpenIDSignUp && !setting.OAuth2.Enabled {
308308
ctx.Error(http.StatusForbidden)
309309
return
310310
}
@@ -768,7 +768,7 @@ func registerRoutes(m *web.Route) {
768768
m.Post("/delete", admin.DeleteApplication)
769769
})
770770
}, func(ctx *context.Context) {
771-
if !setting.OAuth2.Enable {
771+
if !setting.OAuth2.Enabled {
772772
ctx.Error(http.StatusForbidden)
773773
return
774774
}
@@ -779,7 +779,7 @@ func registerRoutes(m *web.Route) {
779779
addSettingsRunnersRoutes()
780780
addSettingsVariablesRoutes()
781781
})
782-
}, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled))
782+
}, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled))
783783
// ***** END: Admin *****
784784

785785
m.Group("", func() {
@@ -891,7 +891,7 @@ func registerRoutes(m *web.Route) {
891891
m.Post("/delete", org.DeleteOAuth2Application)
892892
})
893893
}, func(ctx *context.Context) {
894-
if !setting.OAuth2.Enable {
894+
if !setting.OAuth2.Enabled {
895895
ctx.Error(http.StatusForbidden)
896896
return
897897
}
@@ -943,7 +943,7 @@ func registerRoutes(m *web.Route) {
943943
m.Post("/rebuild", org.RebuildCargoIndex)
944944
})
945945
}, packagesEnabled)
946-
}, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled, "PageIsOrgSettings", true))
946+
}, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled, "PageIsOrgSettings", true))
947947
}, context.OrgAssignment(true, true))
948948
}, reqSignIn)
949949
// ***** END: Organization *****

0 commit comments

Comments
 (0)