token

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADMIN       int = 42
	CREATOR     int = 1
	COORDINATOR int = 2
)

Variables

This section is empty.

Functions

func GetAPIToken

func GetAPIToken(r *http.Request) string

Types

type APIKey

type APIKey struct {
	ID      int    `json:"api_key_id" sql:"api_key_id"`
	Key     string `json:"api_key" sql:"api_key"`
	Comment string `json:"api_key_comment" sql:"api_key_comment"`
}

func APIKeyScan

func APIKeyScan(rs *sql.Rows) (APIKey, error)

type AuthService

type AuthService struct {
	SigningKey        *rsa.PrivateKey
	ValidationKey     *rsa.PublicKey
	ValidationKeyFile string
	TokenLifetime     time.Duration
	Issuer            string
}

func NewAuthService

func NewAuthService(privatekey string, publickey string, tokenLifetime int, issuer string) *AuthService

type Authentication

type Authentication interface {
	GenerateAccessToken(user *User) (string, error)
}

Authentication interface lists the methods that our authentication service should implement

type User

type User struct {
	ID           int       `json:"user_id" sql:"user_id"`
	Email        string    `json:"user_email" sql:"user_email"`
	PasswordHash string    `json:"user_password" sql:"user_password"`
	CreateDate   time.Time `json:"user_createdat" sql:"user_createdat"`
	UpdateDate   time.Time `json:"user_updatedat" sql:"user_updatedat"`
	Role         int       `json:"user_role" sql:"user_role"`
}

func UserScan

func UserScan(rs *sql.Rows) (User, error)

type UserClaims

type UserClaims struct {
	UserID           string
	UserRole         int
	UserZwischentons []int
	UserSituations   []int
	jwt.RegisteredClaims
}

func GetValidClaims

func GetValidClaims(r *http.Request, validator *ValidationService) *UserClaims

type Validation

type Validation interface {
	ValidateAccessToken(token string) (string, error)
}

type ValidationService

type ValidationService struct {
	Key     *rsa.PublicKey
	APIKeys *[]string
}

func NewValidationService

func NewValidationService(auth *AuthService, APIKeys []string) *ValidationService

func (*ValidationService) ValidateAccessToken

func (validator *ValidationService) ValidateAccessToken(tokenString string) (*UserClaims, error)

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

Jump to

Keyboard shortcuts

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