session

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package session defines the opertions for supporting user sessions within a power-league application.

Index

Constants

View Source
const (
	// SessionName is used to update the client session
	SessionName = "client-session"

	// AccessTokenKey updates the access token for the current session
	AccessTokenKey = "access-token"

	// SessionIDKey sets the ID for each session
	SessionIDKey = "session-id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
	Exchange(context.Context, string, ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	Client(ctx context.Context, token *oauth2.Token) *http.Client
}

Consumer is the interface to an OAuth2 consumer

type ConsumerProvider added in v0.4.0

type ConsumerProvider interface {
	Get(r *http.Request) Consumer
}

ConsumerProvider creates Consumers to handle authentication on behalf of a given request

type Manager added in v0.3.0

type Manager interface {
	Login(w http.ResponseWriter, r *http.Request) (loginURL string)
	Authenticate(w http.ResponseWriter, r *http.Request) error
	Logout(w http.ResponseWriter, r *http.Request) error
	IsLoggedIn(r *http.Request) bool
	GetClient(w http.ResponseWriter, r *http.Request) (*goff.Client, error)
}

Manager provides an interface to managing sessions for power rankings users

func NewManager added in v0.3.0

func NewManager(cp ConsumerProvider, s sessions.Store) Manager

NewManager creates a new Manager that uses the given consumer for OAuth authentication and store to persist the sessions across requests. Each session client returned by `Manager.GetClient` will cache responses for up to 6 hours.

See NewManagerWithCache

func NewManagerWithCache added in v0.3.0

func NewManagerWithCache(
	cp ConsumerProvider,
	s sessions.Store,
	userCacheDurationSeconds int,
	cacheSize int64) Manager

NewManagerWithCache creates a new Manager that uses the given consumer provider for OAuth authentication and store to persist the sessions across requests. Each session client returned by `Manager.GetClient` will cache responses for up to `userCacheDurationSeconds` seconds.

Jump to

Keyboard shortcuts

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