func encodeImg(data []byte, format string) string {
	b64Data := base64.StdEncoding.EncodeToString(data)
	return fmt.Sprintf("<img src=\"data:image/%s;base64,%s\" alt=\"Logo\" />", format, b64Data)
}
encodeImg takes the raw image data and converts it to an HTML Img tag with
a base64 data source.
package pagewriter
import (
	_ "embed"
	"encoding/base64"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"html/template"
	"net/http"
	middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
)
var defaultLogoData string
type signInPageWriter struct {
	template *template.Template
	errorPageWriter *errorPageWriter
	proxyPrefix string
	providerName string
	signInMessage string
	footer string
	version string
	displayLoginForm bool
	logoData string
}
func (s *signInPageWriter) WriteSignInPage(rw http.ResponseWriter, req *http.Request, redirectURL string) {
	t := struct {
		ProviderName  string
		SignInMessage template.HTML
		CustomLogin   bool
		Redirect      string
		Version       string
		ProxyPrefix   string
		Footer        template.HTML
		LogoData      template.HTML
	}{
		ProviderName:  s.providerName,
		SignInMessage: template.HTML(s.signInMessage),
		CustomLogin:   s.displayLoginForm,
		Redirect:      redirectURL,
		Version:       s.version,
		ProxyPrefix:   s.proxyPrefix,
		Footer:        template.HTML(s.footer),
		LogoData:      template.HTML(s.logoData),
	}
	err := s.template.Execute(rw, t)
	if err != nil {
		logger.Printf("Error rendering sign-in template: %v", err)
		scope := middlewareapi.GetRequestScope(req)
		s.errorPageWriter.WriteErrorPage(rw, ErrorPageOpts{
			Status:      http.StatusInternalServerError,
			RedirectURL: redirectURL,
			RequestID:   scope.RequestID,
			AppError:    err.Error(),
		})
	}
}
func loadCustomLogo(logoPath string) (string, error) {
	if logoPath == "" {
		return defaultLogoData, nil
	}
	if logoPath == "-" {
		return "", nil
	}
	if strings.HasPrefix(logoPath, "https://") {
		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)
	}
	extension := strings.ToLower(filepath.Ext(logoPath))
	switch extension {
	case ".svg":
		return string(logoData), nil
	case ".jpg", ".jpeg":
		return encodeImg(logoData, "jpeg"), nil
	case ".png":
		return encodeImg(logoData, "png"), nil
	default:
		return "", fmt.Errorf("unknown extension: %q, supported extensions are .svg, .jpg, .jpeg and .png", extension)
	}
}