Skip to content

Commit

Permalink
Disable unnecessary OpenID/OAuth2 elements (#18491)
Browse files Browse the repository at this point in the history
This mod fixes disabling unnecessary OpenID elements.

Related: #13129
Author-Change-Id: IB#1115256
  • Loading branch information
pboguslawski authored Feb 9, 2022
1 parent eb748f5 commit c917f2d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ func RegisterRoutes(m *web.Route) {
bindIgnErr := web.Bind
validation.AddBindingRules()

linkAccountEnabled := func(ctx *context.Context) {
if !setting.Service.EnableOpenIDSignIn && !setting.Service.EnableOpenIDSignUp && !setting.OAuth2.Enable {
ctx.Error(http.StatusForbidden)
return
}
}

openIDSignInEnabled := func(ctx *context.Context) {
if !setting.Service.EnableOpenIDSignIn {
ctx.Error(http.StatusForbidden)
Expand Down Expand Up @@ -279,9 +286,9 @@ func RegisterRoutes(m *web.Route) {
m.Get("/{provider}", auth.SignInOAuth)
m.Get("/{provider}/callback", auth.SignInOAuthCallback)
})
m.Get("/link_account", auth.LinkAccount)
m.Post("/link_account_signin", bindIgnErr(forms.SignInForm{}), auth.LinkAccountPostSignIn)
m.Post("/link_account_signup", bindIgnErr(forms.RegisterForm{}), auth.LinkAccountPostRegister)
m.Get("/link_account", linkAccountEnabled, auth.LinkAccount)
m.Post("/link_account_signin", linkAccountEnabled, bindIgnErr(forms.SignInForm{}), auth.LinkAccountPostSignIn)
m.Post("/link_account_signup", linkAccountEnabled, bindIgnErr(forms.RegisterForm{}), auth.LinkAccountPostRegister)
m.Group("/two_factor", func() {
m.Get("", auth.TwoFactor)
m.Post("", bindIgnErr(forms.TwoFactorAuthForm{}), auth.TwoFactorPost)
Expand Down Expand Up @@ -345,7 +352,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/delete", security.DeleteOpenID)
m.Post("/toggle_visibility", security.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
m.Post("/account_link", security.DeleteAccountLink)
m.Post("/account_link", linkAccountEnabled, security.DeleteAccountLink)
})
m.Group("/applications/oauth2", func() {
m.Get("/{id}", user_setting.OAuth2ApplicationShow)
Expand Down

0 comments on commit c917f2d

Please sign in to comment.