auth

package
v0.0.0-...-3e9cccb Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(key, value interface{}) error
	SetEx(key, value interface{}, lifetime int) error
	GetInt(key interface{}) (int, error)
	GetString(key interface{}) (string, error)
	Delete(key interface{}) error
}

type Service

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

func NewService

func NewService(sessionCache Cache) *Service

func (*Service) CheckPassHash

func (s *Service) CheckPassHash(hash, password []byte) (bool, error)

*

  • Check the password and hash match

func (*Service) CheckUserAuthStatus

func (s *Service) CheckUserAuthStatus(r *http.Request) (int, bool, error)

*

  • Check user's authentication status given *http.Request (containing cookies)

func (*Service) EndUserSession

func (s *Service) EndUserSession(w http.ResponseWriter, r *http.Request,
	userID int) error

*

  • End the user session by removing their session token from the cache,
  • decrementing their session count (used for knowing when it is okay to remove
  • their password-generated key from the cache), and overwrite the cookie on
  • their browser with an immediately-expiring cookie

func (*Service) GetPasswordGeneratedKey

func (s *Service) GetPasswordGeneratedKey(userID int) ([]byte, error)

*

  • Get password-generated encryption key from cache for a given user-ID

func (*Service) HashAndSalt

func (s *Service) HashAndSalt(password []byte) ([]byte, error)

*

func (*Service) InitUserSession

func (s *Service) InitUserSession(w http.ResponseWriter, r *http.Request,
	u *user.User, password []byte) error

*

  • Initialize a user session by storing a session token in the session cache,
  • storing a cookie on the user's browser and storing the password-generated key
  • in the cache

Jump to

Keyboard shortcuts

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