login

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DataFile = "users.json"

Variables

View Source
var ErrSessionNotFound = errors.New("session not found")

Functions

This section is empty.

Types

type Config

type Config struct {
	// CookieName is the name of the cookies created by the store.
	CookieName string `split_words:"true" default:"vvgo-sessions"`

	// CookieDomain is the domain where the cookies can be used.
	// This should be the domain that users visit in their browser.
	CookieDomain string `split_words:"true" default:"localhost"`

	// CookiePath is the url path where the cookies can be used.
	CookiePath string `split_words:"true" default:"/"`
}

type Identity

type Identity struct {
	Kind  Kind   `json:"kind"`
	Roles []Role `json:"roles"`
}

A user identity. This _absolutely_ should not contain any personally identifiable information. Numeric user id's are fine, but no emails, user names, addresses, etc.

func Anonymous

func Anonymous() Identity

func (Identity) HasRole

func (x Identity) HasRole(role Role) bool

func (Identity) IsAnonymous

func (x Identity) IsAnonymous() bool

func (Identity) Role

func (x Identity) Role() Role

Role returns the first role or RoleAnonymous if the identity has no roles.

type Kind

type Kind string

The kind of login This can be used to access additional metadata fields we might add for a particular login.

const (
	KindPassword Kind = "password"
	KindBearer   Kind = "bearer"
	KindBasic    Kind = "basic"
	KindDiscord  Kind = "discord"
)

func (Kind) String

func (x Kind) String() string

type Role

type Role string

A user role. Users can have multiple roles. These provide different levels of access to the api.

const (
	RoleAnonymous     Role = "anonymous" // anonymous/unauthenticated access to the site
	RoleVVGOMember    Role = "vvgo-member"
	RoleVVGOUploader  Role = "vvgo-uploader"
	RoleVVGODeveloper Role = "vvgo-developer"
)

func (Role) String

func (x Role) String() string

type Store

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

Store provides access to the map of session id's to access roles. It can read and validate session cookies from incoming requests,

func NewStore

func NewStore(namespace string, config Config) *Store

NewStore returns a new sessions client.

func (*Store) DeleteSession

func (x *Store) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes the sessionID key from redis.

func (*Store) DeleteSessionFromRequest

func (x *Store) DeleteSessionFromRequest(ctx context.Context, r *http.Request) error

func (*Store) GetSession

func (x *Store) GetSession(ctx context.Context, id string, dest *Identity) error

GetSession reads the login identity for the given session ID.

func (*Store) NewCookie

func (x *Store) NewCookie(ctx context.Context, src *Identity, expires time.Duration) (*http.Cookie, error)

NewCookie returns cookie with a crypto-rand session id.

func (*Store) NewSession

func (x *Store) NewSession(ctx context.Context, src *Identity, expires time.Duration) (string, error)

NewSession returns a new session with a crypto-rand session id.

func (*Store) ReadSessionFromRequest

func (x *Store) ReadSessionFromRequest(ctx context.Context, r *http.Request, dest *Identity) error

ReadSessionFromRequest reads the identity from the sessions db based on the request data.

Jump to

Keyboard shortcuts

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