git.iko.soy/typeable/oauth2-proxy
on master help sign in
Allow specifying URL as input for custom sign in logo (#1330)

* Allow specifying URL as input for custom logos * Fix typo Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> * Update changelog * Only allow HTTPS URLs Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> Co-authored-by: Nick Meves <nicholas.meves@gmail.com>

commit54d44ccb8f5db8e0812aad2e983e8c09970aaf10 authorMiks Kalnins <MiksKalnins@maikumori.com> dateSun 5 Sep 2021, 11:23 (5 years ago) parent7cf3065
6 files changed+19−5
CHANGELOG.md+1 docs/docs/configuration/overview.md+1−1 pkg/apis/options/app.go+3−2 pkg/app/pagewriter/pagewriter.go+2−1 pkg/app/pagewriter/sign_in_page.go+7−1 pkg/app/pagewriter/sign_in_page_test.go+5
CHANGELOG.md+1
@@ -33,6 +33,7 @@
3333- [#1210](https://github.com/oauth2-proxy/oauth2-proxy/pull/1210) New Keycloak OIDC Provider (@pb82)
3434- [#1244](https://github.com/oauth2-proxy/oauth2-proxy/pull/1244) Update Alpine image version to 3.14 (@ahovgaard)
3535- [#1317](https://github.com/oauth2-proxy/oauth2-proxy/pull/1317) Fix incorrect `</form>` tag on the sing_in page when *not* using a custom template (@jord1e)
36+- [#1330](https://github.com/oauth2-proxy/oauth2-proxy/pull/1330) Allow specifying URL as input for custom sign in logo (@MaikuMori)
3637
3738# V7.1.3
3839
docs/docs/configuration/overview.md+1−1
@@ -95,7 +95,7 @@ An example [oauth2-proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/
9595| `--cookie-secure` | bool | set [secure (HTTPS only) cookie flag](https://owasp.org/www-community/controls/SecureFlag) | true |
9696| `--cookie-samesite` | string | set SameSite cookie attribute (`"lax"`, `"strict"`, `"none"`, or `""`). | `""` |
9797| `--custom-templates-dir` | string | path to custom html templates | |
98−| `--custom-sign-in-logo` | string | path to an custom image for the sign_in page logo. Use \"-\" to disable default logo. |
98+| `--custom-sign-in-logo` | string | path or a URL to an custom image for the sign_in page logo. Use \"-\" to disable default logo. |
9999| `--display-htpasswd-form` | bool | display username / password login form if an htpasswd file is provided | true |
100100| `--email-domain` | string \| list | authenticate emails with the specified domain (may be given multiple times). Use `*` to authenticate any email | |
101101| `--errors-to-info-log` | bool | redirects error-level logging to default log channel instead of stderr | |
pkg/apis/options/app.go+3−2
@@ -11,9 +11,10 @@ type Templates struct {
1111 // If either file is missing, the default will be used instead.
1212 Path string `flag:"custom-templates-dir" cfg:"custom_templates_dir"`
1313
14− // CustomLogo is the path to a logo that should replace the default logo
14+ // CustomLogo is the path or a URL to a logo that should replace the default logo
1515 // on the sign_in page template.
1616 // Supported formats are .svg, .png, .jpg and .jpeg.
17+ // If URL is used the format support depends on the browser.
1718 // To disable the default logo, set this value to "-".
1819 CustomLogo string `flag:"custom-sign-in-logo" cfg:"custom_sign_in_logo"`
1920
@@ -40,7 +41,7 @@ func templatesFlagSet() *pflag.FlagSet {
4041 flagSet := pflag.NewFlagSet("templates", pflag.ExitOnError)
4142
4243 flagSet.String("custom-templates-dir", "", "path to custom html templates")
43− flagSet.String("custom-sign-in-logo", "", "path to an custom image for the sign_in page logo. Use \"-\" to disable default logo.")
44+ flagSet.String("custom-sign-in-logo", "", "path or URL to an custom image for the sign_in page logo. Use \"-\" to disable default logo.")
4445 flagSet.String("banner", "", "custom banner string. Use \"-\" to disable default banner.")
4546 flagSet.String("footer", "", "custom footer string. Use \"-\" to disable default footer.")
4647 flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided")
pkg/app/pagewriter/pagewriter.go+2−1
@@ -52,8 +52,9 @@ type Opts struct {
5252 // SignInMessage is the messge displayed above the login button.
5353 SignInMessage string
5454
55− // CustomLogo is the path to a logo to be displayed on the sign in page.
55+ // CustomLogo is the path or URL to a logo to be displayed on the sign in page.
5656 // The logo can be either PNG, JPG/JPEG or SVG.
57+ // If a URL is used, image support depends on the browser.
5758 CustomLogo string
5859}
5960
pkg/app/pagewriter/sign_in_page.go+7−1
@@ -91,7 +91,8 @@ func (s *signInPageWriter) WriteSignInPage(rw http.ResponseWriter, req *http.Req
9191}
9292
9393// loadCustomLogo loads the logo file from the path and encodes it to an HTML
94−// entity. If no custom logo is provided, the OAuth2 Proxy Icon is used instead.
94+// entity or if a URL is provided then it's used directly,
95+// otherwise if no custom logo is provided, the OAuth2 Proxy Icon is used instead.
9596func loadCustomLogo(logoPath string) (string, error) {
9697 if logoPath == "" {
9798 // The default logo is an SVG so this will be valid to just return.
@@ -104,6 +105,11 @@ func loadCustomLogo(logoPath string) (string, error) {
104105 return "", nil
105106 }
106107
108+ if strings.HasPrefix(logoPath, "https://") {
109+ // Return img tag pointing to the URL.
110+ return fmt.Sprintf("<img src=\"%s\" alt=\"Logo\" />", logoPath), nil
111+ }
112+
107113 logoData, err := os.ReadFile(logoPath)
108114 if err != nil {
109115 return "", fmt.Errorf("could not read logo file: %v", err)
pkg/app/pagewriter/sign_in_page_test.go+5
@@ -127,6 +127,11 @@ var _ = Describe("SignIn Page", func() {
127127 expectedErr: nil,
128128 expectedData: "",
129129 }),
130+ Entry("with HTTPS URL", loadCustomLogoTableInput{
131+ logoPath: "https://raw.githubusercontent.com/oauth2-proxy/oauth2-proxy/master/docs/static/img/logos/OAuth2_Proxy_icon.png",
132+ expectedErr: nil,
133+ expectedData: "<img src=\"https://raw.githubusercontent.com/oauth2-proxy/oauth2-proxy/master/docs/static/img/logos/OAuth2_Proxy_icon.png\" alt=\"Logo\" />",
134+ }),
130135 Entry("with an svg custom logo", loadCustomLogoTableInput{
131136 logoPath: "customDir/logo.svg",
132137 expectedErr: nil,