session

package
v0.0.0-...-1564ccb Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSession

func CheckSession(fn func(string, http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

CheckSession is a middleware that checks session token and passes its value to the decorated router function

func CloseSession

func CloseSession(fn func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

CloseSession receives an JWT encoded token and finishes this session

func CreateSession

func CreateSession(id interface{}) (string, string, error)

CreateSession creates a new session and returns the JWT access and refresh token

func Init

func Init(accessSecret, refreshSecret string, accessTokenDuration, refreshTokenDuration time.Duration)

Init defines JWT access secret key and session duration

Types

type Session

type Session struct {
	AccessToken  *Token
	RefreshToken *Token
}

func New

func New(id interface{}) (*Session, error)

New creates a new session fon a given id

func (*Session) Save

func (s *Session) Save() error

Save persists both accessToken and refreshToken in the cache

type Token

type Token struct {
	Uuid      string
	Id        interface{}
	Jwt       string
	ExpiresAt time.Time
}

func LoadToken

func LoadToken(jwtToken, secret string) (*Token, error)

LoadToken receives a jwtToken and decodes its metadata to create a valid Token instance

func NewToken

func NewToken(id interface{}, secret string, duration time.Duration) (*Token, error)

NewToken generates a new Token intance with an auto-generated Uuid

func (*Token) Check

func (t *Token) Check() (string, error)

Check checks if the token is still on the cache

func (*Token) Delete

func (t *Token) Delete() error

Delete removes token from cache

func (*Token) Save

func (t *Token) Save() error

Save persists token in the cache

Jump to

Keyboard shortcuts

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