Auth: Always include oauth and saml settings for frontend (#58705)

* Auth: Always include oauth and saml settings
pull/58268/head
Karl Persson 3 years ago committed by GitHub
parent d999b5bda0
commit 98dbc637cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      pkg/api/frontendsettings.go
  2. 2
      pkg/api/frontendsettings_test.go
  3. 13
      pkg/api/login.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
}

@ -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()

@ -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

Loading…
Cancel
Save