mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-28 09:08:44 +02:00
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>
This commit is contained in:
parent
7cf3065111
commit
54d44ccb8f
@ -33,6 +33,7 @@
|
||||
- [#1210](https://github.com/oauth2-proxy/oauth2-proxy/pull/1210) New Keycloak OIDC Provider (@pb82)
|
||||
- [#1244](https://github.com/oauth2-proxy/oauth2-proxy/pull/1244) Update Alpine image version to 3.14 (@ahovgaard)
|
||||
- [#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)
|
||||
- [#1330](https://github.com/oauth2-proxy/oauth2-proxy/pull/1330) Allow specifying URL as input for custom sign in logo (@MaikuMori)
|
||||
|
||||
# V7.1.3
|
||||
|
||||
|
@ -95,7 +95,7 @@ An example [oauth2-proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/
|
||||
| `--cookie-secure` | bool | set [secure (HTTPS only) cookie flag](https://owasp.org/www-community/controls/SecureFlag) | true |
|
||||
| `--cookie-samesite` | string | set SameSite cookie attribute (`"lax"`, `"strict"`, `"none"`, or `""`). | `""` |
|
||||
| `--custom-templates-dir` | string | path to custom html templates | |
|
||||
| `--custom-sign-in-logo` | string | path to an custom image for the sign_in page logo. Use \"-\" to disable default logo. |
|
||||
| `--custom-sign-in-logo` | string | path or a URL to an custom image for the sign_in page logo. Use \"-\" to disable default logo. |
|
||||
| `--display-htpasswd-form` | bool | display username / password login form if an htpasswd file is provided | true |
|
||||
| `--email-domain` | string \| list | authenticate emails with the specified domain (may be given multiple times). Use `*` to authenticate any email | |
|
||||
| `--errors-to-info-log` | bool | redirects error-level logging to default log channel instead of stderr | |
|
||||
|
@ -11,9 +11,10 @@ type Templates struct {
|
||||
// If either file is missing, the default will be used instead.
|
||||
Path string `flag:"custom-templates-dir" cfg:"custom_templates_dir"`
|
||||
|
||||
// CustomLogo is the path to a logo that should replace the default logo
|
||||
// CustomLogo is the path or a URL to a logo that should replace the default logo
|
||||
// on the sign_in page template.
|
||||
// Supported formats are .svg, .png, .jpg and .jpeg.
|
||||
// If URL is used the format support depends on the browser.
|
||||
// To disable the default logo, set this value to "-".
|
||||
CustomLogo string `flag:"custom-sign-in-logo" cfg:"custom_sign_in_logo"`
|
||||
|
||||
@ -40,7 +41,7 @@ func templatesFlagSet() *pflag.FlagSet {
|
||||
flagSet := pflag.NewFlagSet("templates", pflag.ExitOnError)
|
||||
|
||||
flagSet.String("custom-templates-dir", "", "path to custom html templates")
|
||||
flagSet.String("custom-sign-in-logo", "", "path to an custom image for the sign_in page logo. Use \"-\" to disable default logo.")
|
||||
flagSet.String("custom-sign-in-logo", "", "path or URL to an custom image for the sign_in page logo. Use \"-\" to disable default logo.")
|
||||
flagSet.String("banner", "", "custom banner string. Use \"-\" to disable default banner.")
|
||||
flagSet.String("footer", "", "custom footer string. Use \"-\" to disable default footer.")
|
||||
flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided")
|
||||
|
@ -52,8 +52,9 @@ type Opts struct {
|
||||
// SignInMessage is the messge displayed above the login button.
|
||||
SignInMessage string
|
||||
|
||||
// CustomLogo is the path to a logo to be displayed on the sign in page.
|
||||
// CustomLogo is the path or URL to a logo to be displayed on the sign in page.
|
||||
// The logo can be either PNG, JPG/JPEG or SVG.
|
||||
// If a URL is used, image support depends on the browser.
|
||||
CustomLogo string
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,8 @@ func (s *signInPageWriter) WriteSignInPage(rw http.ResponseWriter, req *http.Req
|
||||
}
|
||||
|
||||
// loadCustomLogo loads the logo file from the path and encodes it to an HTML
|
||||
// entity. If no custom logo is provided, the OAuth2 Proxy Icon is used instead.
|
||||
// entity or if a URL is provided then it's used directly,
|
||||
// otherwise if no custom logo is provided, the OAuth2 Proxy Icon is used instead.
|
||||
func loadCustomLogo(logoPath string) (string, error) {
|
||||
if logoPath == "" {
|
||||
// The default logo is an SVG so this will be valid to just return.
|
||||
@ -104,6 +105,11 @@ func loadCustomLogo(logoPath string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(logoPath, "https://") {
|
||||
// Return img tag pointing to the URL.
|
||||
return fmt.Sprintf("<img src=\"%s\" alt=\"Logo\" />", logoPath), nil
|
||||
}
|
||||
|
||||
logoData, err := os.ReadFile(logoPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not read logo file: %v", err)
|
||||
|
@ -127,6 +127,11 @@ var _ = Describe("SignIn Page", func() {
|
||||
expectedErr: nil,
|
||||
expectedData: "",
|
||||
}),
|
||||
Entry("with HTTPS URL", loadCustomLogoTableInput{
|
||||
logoPath: "https://raw.githubusercontent.com/oauth2-proxy/oauth2-proxy/master/docs/static/img/logos/OAuth2_Proxy_icon.png",
|
||||
expectedErr: nil,
|
||||
expectedData: "<img src=\"https://raw.githubusercontent.com/oauth2-proxy/oauth2-proxy/master/docs/static/img/logos/OAuth2_Proxy_icon.png\" alt=\"Logo\" />",
|
||||
}),
|
||||
Entry("with an svg custom logo", loadCustomLogoTableInput{
|
||||
logoPath: "customDir/logo.svg",
|
||||
expectedErr: nil,
|
||||
|
Loading…
Reference in New Issue
Block a user