Skip to content

Commit 2b2a4a5

Browse files
leytilera6543
andauthored
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 <[email protected]>
1 parent f6ca44c commit 2b2a4a5

File tree

7 files changed

+17
-1
lines changed

7 files changed

+17
-1
lines changed

models/login_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type OAuth2Config struct {
131131
ClientSecret string
132132
OpenIDConnectAutoDiscoveryURL string
133133
CustomURLMapping *oauth2.CustomURLMapping
134+
IconURL string
134135
}
135136

136137
// FromDB fills up an OAuth2Config from serialized format.

models/oauth2.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ func GetActiveOAuth2Providers() ([]string, map[string]OAuth2Provider, error) {
111111
var orderedKeys []string
112112
providers := make(map[string]OAuth2Provider)
113113
for _, source := range loginSources {
114-
providers[source.Name] = OAuth2Providers[source.OAuth2().Provider]
114+
prov := OAuth2Providers[source.OAuth2().Provider]
115+
if source.OAuth2().IconURL != "" {
116+
prov.Image = source.OAuth2().IconURL
117+
}
118+
providers[source.Name] = prov
115119
orderedKeys = append(orderedKeys, source.Name)
116120
}
117121

modules/auth/auth_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type AuthenticationForm struct {
5656
Oauth2AuthURL string
5757
Oauth2ProfileURL string
5858
Oauth2EmailURL string
59+
Oauth2IconURL string
5960
SSPIAutoCreateUsers bool
6061
SSPIAutoActivateUsers bool
6162
SSPIStripDomainNames bool

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ auths.enable_tls = Enable TLS Encryption
22032203
auths.skip_tls_verify = Skip TLS Verify
22042204
auths.pam_service_name = PAM Service Name
22052205
auths.oauth2_provider = OAuth2 Provider
2206+
auths.oauth2_icon_url = Icon URL
22062207
auths.oauth2_clientID = Client ID (Key)
22072208
auths.oauth2_clientSecret = Client Secret
22082209
auths.openIdConnectAutoDiscoveryURL = OpenID Connect Auto Discovery URL

routers/admin/auths.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func parseOAuth2Config(form auth.AuthenticationForm) *models.OAuth2Config {
177177
ClientSecret: form.Oauth2Secret,
178178
OpenIDConnectAutoDiscoveryURL: form.OpenIDConnectAutoDiscoveryURL,
179179
CustomURLMapping: customURLMapping,
180+
IconURL: form.Oauth2IconURL,
180181
}
181182
}
182183

templates/admin/auth/edit.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@
214214
<label for="oauth2_secret">{{.i18n.Tr "admin.auths.oauth2_clientSecret"}}</label>
215215
<input id="oauth2_secret" name="oauth2_secret" value="{{$cfg.ClientSecret}}" required>
216216
</div>
217+
<div class="optional field">
218+
<label for="oauth2_icon_url">{{.i18n.Tr "admin.auths.oauth2_icon_url"}}</label>
219+
<input id="oauth2_icon_url" name="oauth2_icon_url" value="{{$cfg.IconURL}}">
220+
</div>
217221
<div class="open_id_connect_auto_discovery_url required field">
218222
<label for="open_id_connect_auto_discovery_url">{{.i18n.Tr "admin.auths.openIdConnectAutoDiscoveryURL"}}</label>
219223
<input id="open_id_connect_auto_discovery_url" name="open_id_connect_auto_discovery_url" value="{{$cfg.OpenIDConnectAutoDiscoveryURL}}">

templates/admin/auth/source/oauth.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<label for="oauth2_secret">{{.i18n.Tr "admin.auths.oauth2_clientSecret"}}</label>
2121
<input id="oauth2_secret" name="oauth2_secret" value="{{.oauth2_secret}}">
2222
</div>
23+
<div class="optional field">
24+
<label for="oauth2_icon_url">{{.i18n.Tr "admin.auths.oauth2_icon_url"}}</label>
25+
<input id="oauth2_icon_url" name="oauth2_icon_url" value="{{.oauth2_icon_url}}">
26+
</div>
2327
<div class="open_id_connect_auto_discovery_url required field">
2428
<label for="open_id_connect_auto_discovery_url">{{.i18n.Tr "admin.auths.openIdConnectAutoDiscoveryURL"}}</label>
2529
<input id="open_id_connect_auto_discovery_url" name="open_id_connect_auto_discovery_url" value="{{.open_id_connect_auto_discovery_url}}">

0 commit comments

Comments
 (0)