diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index adb51d4cf15..855a9564243 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -198,6 +198,9 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i "unifiedAlerting": map[string]interface{}{ "minInterval": hs.Cfg.UnifiedAlerting.MinInterval.String(), }, + "oauth": hs.getEnabledOAuthProviders(), + "samlEnabled": hs.samlEnabled(), + "samlName": hs.samlName(), } if hs.ThumbService != nil { @@ -501,3 +504,14 @@ func (hs *HTTPServer) pluginSettings(ctx context.Context, orgID int64) (map[stri return pluginSettings, nil } + +func (hs *HTTPServer) getEnabledOAuthProviders() map[string]interface{} { + providers := make(map[string]interface{}) + for key, oauth := range hs.SocialService.GetOAuthInfoProviders() { + providers[key] = map[string]string{ + "name": oauth.Name, + "icon": oauth.Icon, + } + } + return providers +} diff --git a/pkg/api/frontendsettings_test.go b/pkg/api/frontendsettings_test.go index 45db1840bb9..ef37a076523 100644 --- a/pkg/api/frontendsettings_test.go +++ b/pkg/api/frontendsettings_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "testing" + "github.com/grafana/grafana/pkg/login/social" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -57,6 +58,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg, features *featuremgmt. grafanaUpdateChecker: &updatechecker.GrafanaService{}, AccessControl: accesscontrolmock.New().WithDisabled(), PluginSettings: pluginSettings.ProvideService(sqlStore, secretsService), + SocialService: social.ProvideService(cfg), } m := web.New() diff --git a/pkg/api/login.go b/pkg/api/login.go index 559d34ca801..20baa31bde5 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -91,19 +91,6 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) { return } - enabledOAuths := make(map[string]interface{}) - providers := hs.SocialService.GetOAuthInfoProviders() - for key, oauth := range providers { - enabledOAuths[key] = map[string]string{ - "name": oauth.Name, - "icon": oauth.Icon, - } - } - - viewData.Settings["oauth"] = enabledOAuths - viewData.Settings["samlEnabled"] = hs.samlEnabled() - viewData.Settings["samlName"] = hs.samlName() - if loginError, ok := hs.tryGetEncryptedCookie(c, loginErrorCookieName); ok { // this cookie is only set whenever an OAuth login fails // therefore the loginError should be passed to the view data