services

package
v0.0.0-...-5b087d4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenDuration        = time.Hour
	RefreshTokenDuration = time.Hour * 72
	TokenType            = "Bearer"
)

Variables

This section is empty.

Functions

func ContextWithUser

func ContextWithUser(ctx context.Context, u *models.User) context.Context

func ExtractJti

func ExtractJti(cfg *config.Config, tokenStr string) (string, error)

func ExtractRefreshTokenHash

func ExtractRefreshTokenHash(cfg *config.Config, tokenStr string) (string, error)

func ExtractTokenHash

func ExtractTokenHash(cfg *config.Config, tokenStr string) (string, error)

func GetRefreshTokenFromRequest

func GetRefreshTokenFromRequest(cfg *config.Config, r *http.Request) (string, error)

func GetTokenFromRequest

func GetTokenFromRequest(cfg *config.Config, r *http.Request) (string, error)

func UserFromContext

func UserFromContext(ctx context.Context) (*models.User, error)

func UserIdFromContext

func UserIdFromContext(ctx context.Context) (int, error)

Types

type AccessToken

type AccessToken struct {
	AccessToken string `json:"accessToken"`
}

type JWTAuthService

type JWTAuthService interface {
	GenerateTokens(u *models.User) (*Tokens, error)
}

func NewJWTAuthService

func NewJWTAuthService(jwtCfg *config.JWTConfig, redis *database.RedisDB) JWTAuthService

type KAuthTokenClaims

type KAuthTokenClaims struct {
	jwt.StandardClaims
	UID       int    `json:"id"`
	Admin     bool   `json:"admin"`
	TokenHash string `json:"tokenHash"`
}

type RefreshToken

type RefreshToken struct {
	RefreshToken string `json:"refreshToken"`
}

type TokenClaims

type TokenClaims struct {
	jwt.StandardClaims
	UID   int  `json:"id"`
	Admin bool `json:"admin"`
}

type Tokens

type Tokens struct {
	AccessToken  string  `json:"accessToken"`
	RefreshToken string  `json:"refreshToken"`
	ExpiresIn    float64 `json:"expiresIn"`
	TokenType    string  `json:"tokenType"`
}

Jump to

Keyboard shortcuts

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