jwt

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_TOKEN_DISABLED = "ERROR_TOKEN_DISABLED"
	ERROR_USER_DISABLED  = "ERROR_USER_DISABLED"
)
View Source
const QueryAdminJwtByJti string = "select j.admin_id, a.enabled " +
	"FROM jwt_access_token j " +
	"INNER JOIN admins as a ON j.admin_id=a.id " +
	"where j.token_id=?"
View Source
const QueryJwtByJti string = "select j.user_id, u.enabled " +
	"FROM app_jwt_access_token j " +
	"INNER JOIN app_users as u ON j.user_id=u.id " +
	"where j.token_id=? AND j.enabled=1"

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encrypted *string) error

func Encrypt

func Encrypt(raw string) *string

func SetupJWT

func SetupJWT(privateKeyFile, publicKeyFile string)

func ValidateTokenAtDB

func ValidateTokenAtDB(jti string) (types.SqlUuid, bool, error)

Validates the token against the database. Returns user id, if the token is enabled and the err if it fails

Types

type CustomClaims

type CustomClaims struct {
	*jwt.StandardClaims
	TokenType string `json:"type,omitempty"`
	CustomerInfo
	Address   string  `json:"address,omitempty"`
	UserAgent *string `json:"userAgent,omitempty"`
}

func CreateToken

func CreateToken(user string, customerID interface{}, expires uint64, roles *[]uint16) (*string, *CustomClaims, error)

Creates a new Token

func CreateTokenWithResource

func CreateTokenWithResource(user string, customerID interface{}, expires uint64, userAgent *string, roles *[]uint16, resource string) (*string, *CustomClaims, error)

Creates a new Token with resource

Output
	The token
	The Custom Claims struct
	The error in case any error raises

type CustomerInfo

type CustomerInfo struct {
	ID         string       `json:"id"`
	Username   string       `json:"username,omitempty"`
	CustomerID interface{}  `json:"cid,omitempty"`
	Roles      *[]uint16    `json:"sku,omitempty"`
	CustomData *interface{} `json:"customData,omitempty"`
}

CustomerInfo Define some custom types were going to use within our tokens

func VerifyToken

func VerifyToken(dbTokenValidator DBTokenValidator, tokenString *string) (*CustomerInfo, *types.SqlUuid, error)

func VerifyTokenWityIP

func VerifyTokenWityIP(dbTokenValidator DBTokenValidator, tokenString *string, ip string) (*CustomerInfo, *types.SqlUuid, error)

func (*CustomerInfo) ContainsRoleID

func (c *CustomerInfo) ContainsRoleID(roleID uint16) bool

Checks if CustomerInfo object contains any RoleServicesInfo with the

type DBTokenValidator

type DBTokenValidator func(jti string) (*DBTokenValidatorResult, error)

type DBTokenValidatorResult

type DBTokenValidatorResult struct {
	UserID       types.SqlUuid
	PlanID       *uint64
	Enabled      bool
	TokenEnabled bool
}

type JwtProps

type JwtProps struct {
	PrivateKey   *[]byte
	PublicKey    *[]byte
	DbConnection *database.DbPool
	ValidateUrl  *string
	LogLevel     log.LogLevelValue
}

func (*JwtProps) Setup

func (j *JwtProps) Setup()

type ServiceInfo

type ServiceInfo struct {
	ServiceID   uint64 `json:"service"`
	Environment uint8  `json:"env"`
}

Jump to

Keyboard shortcuts

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