token

package
v0.0.0-...-e77dc18 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderName ...
	HeaderName = "Authorization"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenCustomClaims

type AccessTokenCustomClaims struct {
	UserID  string   `json:"user_id,omitempty"`
	KeyType string   `json:"key_type,omitempty"`
	Roles   []string `json:"roles,omitempty"`
	jwt.StandardClaims
}

AccessTokenCustomClaims specifies the claims for access token

type Extractor

type Extractor interface {
	ExtractGRPC(ctx context.Context) (header string, err error)
	ExtractHTTP(r *http.Request) (header string, err error)
}

Extractor ...

func NewExtractor

func NewExtractor() Extractor

NewToken ...

type JWTManager

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

func NewJWTManager

func NewJWTManager(logger hclog.Logger, configs *utils.Configurations) *JWTManager

func (*JWTManager) GenerateAccessToken

func (j *JWTManager) GenerateAccessToken(user *data.User) (string, error)

GenerateAccessToken generates a new access token for the given user

func (*JWTManager) GenerateCustomKey

func (j *JWTManager) GenerateCustomKey(userID string, tokenHash string) string

GenerateCustomKey creates a new key for our jwt payload the key is a hashed combination of the userID and user tokenhash

func (*JWTManager) GenerateRefreshToken

func (j *JWTManager) GenerateRefreshToken(user *data.User) (string, error)

GenerateRefreshToken generate a new refresh token for the given user

func (*JWTManager) ValidateAccessToken

func (j *JWTManager) ValidateAccessToken(tokenString string) (*AccessTokenCustomClaims, error)

ValidateAccessToken parses and validates the given access token returns the userId present in the token payload

func (*JWTManager) ValidateRefreshToken

func (j *JWTManager) ValidateRefreshToken(tokenString string) (*RefreshTokenCustomClaims, error)

ValidateRefreshToken parses and validates the given refresh token returns the userId and customkey present in the token payload

type RefreshTokenCustomClaims

type RefreshTokenCustomClaims struct {
	UserID    string `json:"user_id,omitempty"`
	CustomKey string `json:"custom_key,omitempty"`
	KeyType   string `json:"key_type,omitempty"`
	jwt.StandardClaims
}

RefreshTokenCustomClaims specifies the claims for refresh token

type TokenManager

type TokenManager interface {
	GenerateAccessToken(user *data.User) (string, error)
	GenerateRefreshToken(user *data.User) (string, error)
	GenerateCustomKey(userID string, password string) string
	ValidateAccessToken(token string) (string, error)
	ValidateRefreshToken(token string) (string, string, error)
}

Authentication interface lists the methods that our authentication service should implement

type User

type User struct {
	Username       string
	HashedPassword string
	Roles          []string
}

Jump to

Keyboard shortcuts

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