session

package
v0.0.0-...-1045ef1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSessionJWTToken

func CreateSessionJWTToken(SigningKey string, sessionTkn Token) (string, error)

CreateSessionJWTToken creates a new jwt token used in a user session instance

func DecodeJWTToken

func DecodeJWTToken(signKey string, tknStr string) (jwt.Token, error)

DecodeJWTToken decodes a jwt token using the signing key

func DecodeJWTWithPubKey

func DecodeJWTWithPubKey(pubKey string, tknStr string) (claims jwt.Claims, err error)

DecodeJWTWithPubKey gets the claims of a jwt auth token

func DecodePublicKey

func DecodePublicKey(str string) (*rsa.PublicKey, error)

DecodePublicKey decodes an ssh-rsa string into rsa public key

func Delete

func Delete(id string) error

Delete removes a user session from the db

func Exist

func Exist(id string) bool

Exist returns true if a session exist in the db

func IsValidTokenFormat

func IsValidTokenFormat(tkn string) bool

IsValidTokenFormat checks if a token is a well formatted Bearer token

func ParseTokenTypeAndValue

func ParseTokenTypeAndValue(tkn string) (tokenType string, tokenValue string)

ParseTokenTypeAndValue returns the type and value of a jwt token

func Save

func Save(session Session) error

Save saves a user session into the db

Types

type Claims

type Claims struct {
	Phrase string `json:"phrase"`
	jwt.StandardClaims
}

Claims custom claims for user authentication

func VerifyAuthTokenWithAuthorizedKeys

func VerifyAuthTokenWithAuthorizedKeys(keys []string, tkn string) (claims *Claims)

VerifyAuthTokenWithAuthorizedKeys gets the auth claims from jwt token using an authorized key from server

type CustomClaims

type CustomClaims struct {
	Data interface{} `json:"data"`
	jwt.StandardClaims
}

CustomClaims custom claims for request

type Session

type Session struct {
	ID        string `json:"id"`
	User      string `json:"user"`
	Token     string `json:"token"`
	ExpiresAt string `json:"expires_at"`
}

Session represents an authenticated user session

func GetAllSessions

func GetAllSessions() ([]Session, error)

GetAllSessions returns all user sessions

func GetSessionByID

func GetSessionByID(id string) (Session, error)

GetSessionByID returns a user session by id

func (Session) IsValid

func (s Session) IsValid() bool

type Token

type Token struct {
	SessionID string `json:"session_id"` // uuid identifying the session jwt
}

Token for an authenticated session

func ParseSessionTokenFromJWTClaims

func ParseSessionTokenFromJWTClaims(tkn jwt.Token) (Token, error)

ParseTokenTypeAndValue returns the session token within the jwt claims

Jump to

Keyboard shortcuts

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