jawsauth

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 12 Imported by: 1

README

build coverage goreport Docs

jawsauth

OAuth2 integration with Jaws sessions using "golang.org/x/oauth2".

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInconsistentState = errors.New("oauth2 inconsistent state")

Functions

This section is empty.

Types

type Config

func (*Config) Build

func (cfg *Config) Build(overrideUrl string) (oauth2cfg *oauth2.Config, err error)

Build creates a oauth2.Config. If overrideUrl is provided, it's scheme, host and port are used instead of the ones in RedirectURL. This is useful when testing.

func (*Config) Validate

func (cfg *Config) Validate() (err error)

type EventFunc added in v0.3.0

type EventFunc func(sess *jaws.Session, hr *http.Request)

type HandleFunc

type HandleFunc func(uri string, handler http.Handler)

type Server

type Server struct {
	Jaws            *jaws.Jaws
	SessionKey      string              // default is "oauth2userinfo", value will be of type map[string]any
	SessionEmailKey string              // default is "email", value will be of type string
	HandledPaths    map[string]struct{} // URI paths we have registered handlers for
	LoginEvent      EventFunc           // if not nil, called after a successful login
	LogoutEvent     EventFunc           // if not nil, called before logout
	// contains filtered or unexported fields
}

func New

func New(jw *jaws.Jaws, cfg *Config, handleFn HandleFunc) (srv *Server, err error)

func NewDebug added in v0.2.0

func NewDebug(jw *jaws.Jaws, cfg *Config, handleFn HandleFunc, overrideUrl string) (srv *Server, err error)

func (*Server) HandleAuthResponse

func (srv *Server) HandleAuthResponse(hw http.ResponseWriter, hr *http.Request)

func (*Server) HandleLogin

func (srv *Server) HandleLogin(hw http.ResponseWriter, hr *http.Request)

func (*Server) HandleLogout

func (srv *Server) HandleLogout(hw http.ResponseWriter, hr *http.Request)

func (*Server) Handler

func (srv *Server) Handler(name string, dot any) http.Handler

Handler returns a http.Handler using a jaws.Template that requires an authenticated user. Sets the jaws Session value srv.SessionKey to what UserInfoURL returned.

func (*Server) Valid added in v0.2.0

func (srv *Server) Valid() bool

Valid returns true if OAuth2 is configured.

func (*Server) Wrap

func (srv *Server) Wrap(h http.Handler) (rh http.Handler)

Wrap returns a http.Handler that requires an authenticated user before invoking h. Sets the jaws Session value srv.SessionKey to what UserInfoURL returned. If the Server is not Valid, returns h.

Jump to

Keyboard shortcuts

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