manager

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomStringURLSafe

func GenerateRandomStringURLSafe(n int) (string, error)

GenerateRandomStringURLSafe returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func NewRedisClient

func NewRedisClient(address string) *redis.Client

NewRedisClient creates a new redis client

func NewRedisStore

func NewRedisStore(ctx context.Context, client *redis.Client) (*redisstore.RedisStore, error)

NewRedisStore creates new default RedisStore

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	ID          int    `json:"ID"`
	Role        string `json:"roles"`
	RandomToken string `json:"token"`
}

Claims defines the custom JWT claims

type Config

type Config struct {
	JWT   JWT
	Redis Redis
}

Config returns the module config

func NewConfig

func NewConfig() *Config

NewConfig returns a loaded module config

type JWT

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

JWT is a JSON web token manager

func NewJWTManager

func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWT

NewJWTManager returns a new JWT manager

func (*JWT) Generate

func (jwt *JWT) Generate(ID int, role string, randToken string) (string, error)

Generate generates and signs a new token with specified claims for a user

func (*JWT) GetSecretKey

func (jwt *JWT) GetSecretKey() []byte

GetSecretKey returns secret key to sign jwt

func (*JWT) Verify

func (jwt *JWT) Verify(tokenStr string) (*Claims, error)

Verify verifies the access token string and return a user claim if the token is valid

type Redis

type Redis struct {
	Address          string `env:"GRAL_REDIS_ADDRESS"`
	DefaultSessionID string `env:"GRAL_DEFAULT_SESSION_ID"`
	SessionTimeout   int    `env:"GRAL_SESSION_TIMEOUT"`
	CSRFTokenLength  int    `env:"GRAL_CSRF_TOKEN_LENGTH"`
}

Redis config

Jump to

Keyboard shortcuts

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