Skip to content

Commit a51b115

Browse files
Use inline SVG for built-in OAuth providers (#25171)
The plan is that all built-in auth providers use inline SVG for more flexibility in styling and to get the GitHub icon to follow `currentcolor`. This only removes the `public/img/auth` directory and adds the missing svgs to our svg build. It should map the built-in providers to these SVGs and render them. If the user has set a Icon URL, it should render that as an `img` tag instead. ``` gitea-azure-ad gitea-bitbucket gitea-discord gitea-dropbox gitea-facebook gitea-gitea gitea-gitlab gitea-google gitea-mastodon gitea-microsoftonline gitea-nextcloud gitea-twitter gitea-yandex octicon-mark-github ``` GitHub logo is now white again on dark theme: <img width="431" alt="Screenshot 2023-06-12 at 21 45 34" src="https://github.com/go-gitea/gitea/assets/115237/27a43504-d60a-4132-a502-336b25883e4d"> --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 2ad2d5a commit a51b115

34 files changed

+57
-27
lines changed

modules/svg/svg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ func RenderHTML(icon string, others ...interface{}) template.HTML {
6262
}
6363
return template.HTML(svgStr)
6464
}
65-
return template.HTML("")
65+
return ""
6666
}

public/img/auth/azureadv2.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/img/auth/gitea.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/img/auth/github.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/img/auth/gitlab.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/img/svg/gitea-azuread.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-azureadv2.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-bitbucket.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-discord.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-dropbox.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-facebook.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-google.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-mastodon.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-microsoftonline.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-nextcloud.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-twitter.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/svg/gitea-yandex.svg

Lines changed: 1 addition & 0 deletions
Loading

services/auth/source/oauth2/providers.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ package oauth2
55

66
import (
77
"errors"
8+
"fmt"
9+
"html"
10+
"html/template"
811
"net/url"
912
"sort"
1013

@@ -19,7 +22,7 @@ import (
1922
type Provider interface {
2023
Name() string
2124
DisplayName() string
22-
IconURL() string
25+
IconHTML() template.HTML
2326
CustomURLSettings() *CustomURLSettings
2427
}
2528

@@ -35,7 +38,7 @@ type GothProvider interface {
3538
}
3639

3740
// AuthSourceProvider provides a provider for an AuthSource. Multiple auth sources could use the same registered GothProvider
38-
// So each auth source should have its own DisplayName and IconURL for display.
41+
// So each auth source should have its own DisplayName and IconHTML for display.
3942
// The Name is the GothProvider's name, to help to find the GothProvider to sign in.
4043
// The DisplayName is the auth source config's name, site admin set it on the admin page, the IconURL can also be set there.
4144
type AuthSourceProvider struct {
@@ -51,11 +54,14 @@ func (p *AuthSourceProvider) DisplayName() string {
5154
return p.sourceName
5255
}
5356

54-
func (p *AuthSourceProvider) IconURL() string {
57+
func (p *AuthSourceProvider) IconHTML() template.HTML {
5558
if p.iconURL != "" {
56-
return p.iconURL
59+
img := fmt.Sprintf(`<img class="gt-mr-3" width="20" height="20" src="%s" alt="%s">`,
60+
html.EscapeString(p.iconURL), html.EscapeString(p.DisplayName()),
61+
)
62+
return template.HTML(img)
5763
}
58-
return p.GothProvider.IconURL()
64+
return p.GothProvider.IconHTML()
5965
}
6066

6167
// Providers contains the map of registered OAuth2 providers in Gitea (based on goth)

0 commit comments

Comments
 (0)