From 0109a9b9a21af4ab2a3e680e6001b53d2e8d391c Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Tue, 22 Dec 2020 23:17:18 +0300 Subject: [PATCH 1/8] Fix creating OAuth2 auth source from CLI --- models/oauth2.go | 12 +++++++++++- modules/auth/oauth2/oauth2.go | 5 +++++ routers/user/auth.go | 11 +++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/models/oauth2.go b/models/oauth2.go index 65d62fdb617e0..218337cc607b2 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -125,8 +125,18 @@ func InitOAuth2() error { if err := oauth2.Init(x); err != nil { return err } - loginSources, _ := GetActiveOAuth2ProviderLoginSources() + return initOuath2LoginSources() +} +// ResetOAuth2 clears existing OAuth2 providers and loads them from the DB +func ResetOAuth2() error { + oauth2.ClearProviders() + return initOuath2LoginSources() +} + +// initOuath2LoginSources is used to load and register all active OAuth2 providers +func initOuath2LoginSources() error { + loginSources, _ := GetActiveOAuth2ProviderLoginSources() for _, source := range loginSources { oAuth2Config := source.OAuth2() err := oauth2.RegisterProvider(source.Name, oAuth2Config.Provider, oAuth2Config.ClientID, oAuth2Config.ClientSecret, oAuth2Config.OpenIDConnectAutoDiscoveryURL, oAuth2Config.CustomURLMapping) diff --git a/modules/auth/oauth2/oauth2.go b/modules/auth/oauth2/oauth2.go index f69bc61d7549b..e2c97b72f31d2 100644 --- a/modules/auth/oauth2/oauth2.go +++ b/modules/auth/oauth2/oauth2.go @@ -119,6 +119,11 @@ func RemoveProvider(providerName string) { delete(goth.GetProviders(), providerName) } +// ClearProviders clears all OAuth2 providers from the goth lib +func ClearProviders() { + goth.ClearProviders() +} + // used to create different types of goth providers func createProvider(providerName, providerType, clientID, clientSecret, openIDConnectAutoDiscoveryURL string, customURLMapping *CustomURLMapping) (goth.Provider, error) { callbackURL := setting.AppURL + "user/oauth2/" + url.PathEscape(providerName) + "/callback" diff --git a/routers/user/auth.go b/routers/user/auth.go index acd88b364c3b1..dcd11fbcf6374 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -570,8 +570,15 @@ func SignInOAuth(ctx *context.Context) { return } - err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp) - if err != nil { + if err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp); err != nil { + if strings.Contains(err.Error(), "no provider for ") { + if err = models.ResetOAuth2(); err != nil { + ctx.ServerError("SignIn", err) + } + if err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp); err != nil { + ctx.ServerError("SignIn", err) + } + } ctx.ServerError("SignIn", err) } // redirect is done in oauth2.Auth From 049710170b576b241f387fe6242a04cfaf45af40 Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Wed, 23 Dec 2020 08:06:03 +0300 Subject: [PATCH 2/8] Fix MR discussions --- routers/user/auth.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routers/user/auth.go b/routers/user/auth.go index dcd11fbcf6374..540a0d2f1a8e5 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -574,10 +574,12 @@ func SignInOAuth(ctx *context.Context) { if strings.Contains(err.Error(), "no provider for ") { if err = models.ResetOAuth2(); err != nil { ctx.ServerError("SignIn", err) + return } if err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp); err != nil { ctx.ServerError("SignIn", err) } + return } ctx.ServerError("SignIn", err) } From 6cc8df8d4b98f628317004cfa090c4026d7ebfc8 Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Thu, 24 Dec 2020 07:31:26 +0300 Subject: [PATCH 3/8] Fix typo --- models/oauth2.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/oauth2.go b/models/oauth2.go index 218337cc607b2..2bf22a66661c1 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -125,17 +125,17 @@ func InitOAuth2() error { if err := oauth2.Init(x); err != nil { return err } - return initOuath2LoginSources() + return initOAuth2LoginSources() } // ResetOAuth2 clears existing OAuth2 providers and loads them from the DB func ResetOAuth2() error { oauth2.ClearProviders() - return initOuath2LoginSources() + return initOAuth2LoginSources() } // initOuath2LoginSources is used to load and register all active OAuth2 providers -func initOuath2LoginSources() error { +func initOAuth2LoginSources() error { loginSources, _ := GetActiveOAuth2ProviderLoginSources() for _, source := range loginSources { oAuth2Config := source.OAuth2() From f5d57a9a052623be91121ecda38f914871c3e4c7 Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Thu, 24 Dec 2020 08:14:18 +0300 Subject: [PATCH 4/8] Fix typo in comment --- models/oauth2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/oauth2.go b/models/oauth2.go index 2bf22a66661c1..844abd935eea8 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -134,7 +134,7 @@ func ResetOAuth2() error { return initOAuth2LoginSources() } -// initOuath2LoginSources is used to load and register all active OAuth2 providers +// initOAuth2LoginSources is used to load and register all active OAuth2 providers func initOAuth2LoginSources() error { loginSources, _ := GetActiveOAuth2ProviderLoginSources() for _, source := range loginSources { From c8819d2143b9ca36278bf420d2de411f16102155 Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Thu, 24 Dec 2020 21:58:06 +0300 Subject: [PATCH 5/8] Change comment --- models/oauth2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/oauth2.go b/models/oauth2.go index 844abd935eea8..27668d5eecc60 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -128,7 +128,7 @@ func InitOAuth2() error { return initOAuth2LoginSources() } -// ResetOAuth2 clears existing OAuth2 providers and loads them from the DB +// ResetOAuth2 clears existing OAuth2 providers and loads them from DB func ResetOAuth2() error { oauth2.ClearProviders() return initOAuth2LoginSources() From 4439e52a75ec2fac34d1b93be96b40bd67fb2d29 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 25 Dec 2020 04:58:30 +0800 Subject: [PATCH 6/8] Fix heatmap total contributions (#14141) --- web_src/js/components/ActivityHeatmap.vue | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue index 943bf704e2811..7eb129d1397bd 100644 --- a/web_src/js/components/ActivityHeatmap.vue +++ b/web_src/js/components/ActivityHeatmap.vue @@ -1,7 +1,7 @@