services

package
Version: v0.0.0-...-7a7783f Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

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

Various token constants

Variables

This section is empty.

Functions

func ContextWithUser

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

ContextWithUser returns the copy of the given context with the user key value being the user

func ContextWithUserID

func ContextWithUserID(ctx context.Context, uID string) context.Context

ContextWithUserID returns the copy of the given context with the id key value being the uid

func ExtractRefreshTokenHash

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

ExtractRefreshTokenHash returns the refresh token hash from the given signed token string Signing method is RSA

func ExtractTokenHash

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

ExtractTokenHash returns the access token hash from the given signed token string Signing method is HMAC

func GetRefreshTokenFromRequest

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

GetRefreshTokenFromRequest returns the refresh token string from the request header Signing method is RSA

func GetTokenFromRequest

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

GetTokenFromRequest returns the access token string from the request header Signing method is HMAC

func UserFromContext

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

UserFromContext returns the uid from the context user key

func UserIDFromContext

func UserIDFromContext(ctx context.Context) (string, error)

UserIDFromContext returns the uid from the context id key

Types

type AccessToken

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

AccessToken stores the access token

type JWTAuthService

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

JWTAuthService is the public interface for auth services

func NewJWTAuthService

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

NewJWTAuthService returns a new JWT auth service

type KAuthTokenClaims

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

KAuthTokenClaims stores the claims associated with a token

type RefreshToken

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

RefreshToken stores the refresh token

type Tokens

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

Tokens stores the access and refresh tokens, experation, and type

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL