From 90bf1e7961cf428c378e93726dcb7f2cb6da24c1 Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 26 Feb 2021 10:44:45 +0000 Subject: [PATCH] Disable broken OAuth2 providers at startup (#14802) (#14811) Backport #14802 Instead of causing a log.Fatal, we should handle broken OAuth2 providers by disabling them. Fix #8930 Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick --- models/oauth2.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/models/oauth2.go b/models/oauth2.go index 21a6f995c7e..3869710d869 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -8,6 +8,7 @@ import ( "sort" "code.gitea.io/gitea/modules/auth/oauth2" + "code.gitea.io/gitea/modules/log" ) // OAuth2Provider describes the display values of a single OAuth2 provider @@ -135,7 +136,12 @@ func initOAuth2LoginSources() error { oAuth2Config := source.OAuth2() err := oauth2.RegisterProvider(source.Name, oAuth2Config.Provider, oAuth2Config.ClientID, oAuth2Config.ClientSecret, oAuth2Config.OpenIDConnectAutoDiscoveryURL, oAuth2Config.CustomURLMapping) if err != nil { - return err + log.Critical("Unable to register source: %s due to Error: %v. This source will be disabled.", source.Name, err) + source.IsActived = false + if err = UpdateSource(source); err != nil { + log.Critical("Unable to update source %s to disable it. Error: %v", err) + return err + } } } return nil