From 2b2a4a53bfea37b64965a9e04aed93b7455048df Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Mon, 28 Dec 2020 03:35:55 +0100 Subject: [PATCH] Custom icons for OAuth sources (#14161) * Add Icon URL to Backend * Template for Icon URL * Localization & Edit Icon URL * Improve Custom Icon URL * Removed not working else Co-authored-by: 6543 <6543@obermui.de> --- models/login_source.go | 1 + models/oauth2.go | 6 +++++- modules/auth/auth_form.go | 1 + options/locale/locale_en-US.ini | 1 + routers/admin/auths.go | 1 + templates/admin/auth/edit.tmpl | 4 ++++ templates/admin/auth/source/oauth.tmpl | 4 ++++ 7 files changed, 17 insertions(+), 1 deletion(-) diff --git a/models/login_source.go b/models/login_source.go index 4f577d6ca7..f1941c3e78 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -131,6 +131,7 @@ type OAuth2Config struct { ClientSecret string OpenIDConnectAutoDiscoveryURL string CustomURLMapping *oauth2.CustomURLMapping + IconURL string } // FromDB fills up an OAuth2Config from serialized format. diff --git a/models/oauth2.go b/models/oauth2.go index 27668d5eec..241e11a44d 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -111,7 +111,11 @@ func GetActiveOAuth2Providers() ([]string, map[string]OAuth2Provider, error) { var orderedKeys []string providers := make(map[string]OAuth2Provider) for _, source := range loginSources { - providers[source.Name] = OAuth2Providers[source.OAuth2().Provider] + prov := OAuth2Providers[source.OAuth2().Provider] + if source.OAuth2().IconURL != "" { + prov.Image = source.OAuth2().IconURL + } + providers[source.Name] = prov orderedKeys = append(orderedKeys, source.Name) } diff --git a/modules/auth/auth_form.go b/modules/auth/auth_form.go index 1d02c7acf3..e348b01e91 100644 --- a/modules/auth/auth_form.go +++ b/modules/auth/auth_form.go @@ -56,6 +56,7 @@ type AuthenticationForm struct { Oauth2AuthURL string Oauth2ProfileURL string Oauth2EmailURL string + Oauth2IconURL string SSPIAutoCreateUsers bool SSPIAutoActivateUsers bool SSPIStripDomainNames bool diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3aff43c0a8..ae72dff3ad 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2203,6 +2203,7 @@ auths.enable_tls = Enable TLS Encryption auths.skip_tls_verify = Skip TLS Verify auths.pam_service_name = PAM Service Name auths.oauth2_provider = OAuth2 Provider +auths.oauth2_icon_url = Icon URL auths.oauth2_clientID = Client ID (Key) auths.oauth2_clientSecret = Client Secret auths.openIdConnectAutoDiscoveryURL = OpenID Connect Auto Discovery URL diff --git a/routers/admin/auths.go b/routers/admin/auths.go index ce9dd38360..7a9d286373 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -177,6 +177,7 @@ func parseOAuth2Config(form auth.AuthenticationForm) *models.OAuth2Config { ClientSecret: form.Oauth2Secret, OpenIDConnectAutoDiscoveryURL: form.OpenIDConnectAutoDiscoveryURL, CustomURLMapping: customURLMapping, + IconURL: form.Oauth2IconURL, } } diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl index 3347a91bf6..6b24858395 100644 --- a/templates/admin/auth/edit.tmpl +++ b/templates/admin/auth/edit.tmpl @@ -214,6 +214,10 @@ +
+ + +
diff --git a/templates/admin/auth/source/oauth.tmpl b/templates/admin/auth/source/oauth.tmpl index 7870dbd65d..1489ab8394 100644 --- a/templates/admin/auth/source/oauth.tmpl +++ b/templates/admin/auth/source/oauth.tmpl @@ -20,6 +20,10 @@
+
+ + +