auth

package module
v0.0.0-...-a2dcc08 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 4 Imported by: 0

README

auth

A wrapper around gorilla sessions to help manage authentication.

Provider

The provider is something that will live in the consumers code. Therefore this is just an interface.

If you want to maintain anything on the request context, you can do it.

type key int

const ( ContextKey = key(22) )

func (p ProviderImpl) setUser(usr User, r *http.Request) { ctx := r.Context() ctx = context.WithValue(ctx, ContextKey, usr) *r = *(r.WithContext(ctx)) }

// Then to get this from the context:

func FromContext(ctx context.Context) (User, bool) { usr, ok := ctx.Value(ContextKey).(User) return usr, ok }

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthFailed = errors.New("Auth failed")
View Source
var TokenUnavailable = errors.New("Token Unavailable")
View Source
var TokenUnrecognized = errors.New("Token Unrecognized")

Functions

This section is empty.

Types

type Flashes

type Flashes interface {
	SetErrorFlash(w http.ResponseWriter, r *http.Request, message string)
	SetSuccessFlash(w http.ResponseWriter, r *http.Request, message string)
}

type Manager

type Manager interface {
	DoLogin(w http.ResponseWriter, r *http.Request, token string) error
	DoLogout(w http.ResponseWriter, r *http.Request) error
	PageAuth(next http.Handler) http.Handler
	OverridePagAuth(provider Provider) func(next http.Handler) http.Handler
	ApiAuth(next http.Handler) http.Handler
	OverrideApiAuth(provider Provider) func(next http.Handler) http.Handler
}

func NewSessionManager

func NewSessionManager(store sessions.Store, provider Provider, redirect string, flashes Flashes) Manager

func NewSessionManagerOverrideSessionKey

func NewSessionManagerOverrideSessionKey(store sessions.Store, provider Provider, redirect string, flashes Flashes, overrideSessionKey string) Manager

type Provider

type Provider interface {
	IsValid(token string, r *http.Request) (bool, error)
}

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

func (*SessionManager) ApiAuth

func (s *SessionManager) ApiAuth(next http.Handler) http.Handler

func (*SessionManager) DoLogin

func (s *SessionManager) DoLogin(w http.ResponseWriter, r *http.Request, token string) error

func (*SessionManager) DoLogout

func (s *SessionManager) DoLogout(w http.ResponseWriter, r *http.Request) error

func (*SessionManager) OverrideApiAuth

func (s *SessionManager) OverrideApiAuth(provider Provider) func(next http.Handler) http.Handler

func (*SessionManager) OverridePagAuth

func (s *SessionManager) OverridePagAuth(provider Provider) func(next http.Handler) http.Handler

func (*SessionManager) PageAuth

func (s *SessionManager) PageAuth(next http.Handler) http.Handler

Jump to

Keyboard shortcuts

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