From 9c4da36001ffaa5c6b4301b5a4355c5b94822bc4 Mon Sep 17 00:00:00 2001 From: Balki <189196+balki@users.noreply.github.com> Date: Wed, 17 Aug 2022 01:42:37 +0000 Subject: [PATCH] Fix panic when an invalid oauth2 name is passed --- models/auth/oauth2.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go index 5a58ec62b7d1d..ad1d80e25a85b 100644 --- a/models/auth/oauth2.go +++ b/models/auth/oauth2.go @@ -512,10 +512,14 @@ func GetActiveOAuth2ProviderSources() ([]*Source, error) { func GetActiveOAuth2SourceByName(name string) (*Source, error) { authSource := new(Source) has, err := db.GetEngine(db.DefaultContext).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(authSource) - if !has || err != nil { + if err != nil { return nil, err } + if !has { + return nil, fmt.Errorf("oauth2 source not found, name: %q", name) + } + return authSource, nil }