pagewriter

package
v7.0.0-...-1c7ecba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorPageOpts

type ErrorPageOpts struct {
	// HTTP status code
	Status int
	// Redirect URL for "Go back" and "Sign in" buttons
	RedirectURL string
	// The UUID of the request
	RequestID string
	// App Error shown in debug mode
	AppError string
	// Generic error messages shown in non-debug mode
	Messages []interface{}
}

ErrorPageOpts bundles up all the content needed to write the Error Page

type Opts

type Opts struct {
	// TemplatesPath is the path from which to load custom templates for the sign-in and error pages.
	TemplatesPath string

	// ProxyPrefix is the prefix under which OAuth2 Proxy pages are served.
	ProxyPrefix string

	// Footer is the footer to be displayed at the bottom of the page.
	// If not set, a default footer will be used.
	Footer string

	// Version is the OAuth2 Proxy version to be used in the default footer.
	Version string

	// Debug determines whether errors pages should be rendered with detailed
	// errors.
	Debug bool

	// DisplayLoginForm determines whether or not the basic auth password form is displayed on the sign-in page.
	DisplayLoginForm bool

	// ProviderName is the name of the provider that should be displayed on the login button.
	ProviderName string

	// SignInMessage is the messge displayed above the login button.
	SignInMessage string

	// The logo can be either PNG, JPG/JPEG or SVG.
	// If a URL is used, image support depends on the browser.
	CustomLogo string
}

Opts contains all options required to configure the template rendering within OAuth2 Proxy.

type Writer

type Writer interface {
	WriteSignInPage(rw http.ResponseWriter, req *http.Request, redirectURL string, statusCode int)
	WriteErrorPage(rw http.ResponseWriter, opts ErrorPageOpts)
	ProxyErrorHandler(rw http.ResponseWriter, req *http.Request, proxyErr error)
	WriteRobotsTxt(rw http.ResponseWriter, req *http.Request)
}

Writer is an interface for rendering html templates for both sign-in and error pages. It can also be used to write errors for the http.ReverseProxy used in the upstream package.

func NewWriter

func NewWriter(opts Opts) (Writer, error)

NewWriter constructs a Writer from the options given to allow rendering of sign-in and error pages.

type WriterFuncs

type WriterFuncs struct {
	SignInPageFunc func(rw http.ResponseWriter, req *http.Request, redirectURL string, statusCode int)
	ErrorPageFunc  func(rw http.ResponseWriter, opts ErrorPageOpts)
	ProxyErrorFunc func(rw http.ResponseWriter, req *http.Request, proxyErr error)
	RobotsTxtfunc  func(rw http.ResponseWriter, req *http.Request)
}

WriterFuncs is an implementation of the PageWriter interface based on override functions. If any of the funcs are not provided, a default implementation will be used. This is primarily for us in testing.

func (*WriterFuncs) ProxyErrorHandler

func (w *WriterFuncs) ProxyErrorHandler(rw http.ResponseWriter, req *http.Request, proxyErr error)

ProxyErrorHandler implements the Writer interface. If the ProxyErrorFunc is provided, this will be used, else a default implementation will be used.

func (*WriterFuncs) WriteErrorPage

func (w *WriterFuncs) WriteErrorPage(rw http.ResponseWriter, opts ErrorPageOpts)

WriteErrorPage implements the Writer interface. If the ErrorPageFunc is provided, this will be used, else a default implementation will be used.

func (*WriterFuncs) WriteRobotsTxt

func (w *WriterFuncs) WriteRobotsTxt(rw http.ResponseWriter, req *http.Request)

WriteRobotsTxt implements the Writer interface. If the RobotsTxtfunc is provided, this will be used, else a default implementation will be used.

func (*WriterFuncs) WriteSignInPage

func (w *WriterFuncs) WriteSignInPage(rw http.ResponseWriter, req *http.Request, redirectURL string, statusCode int)

WriteSignInPage implements the Writer interface. If the SignInPageFunc is provided, this will be used, else a default implementation will be used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL