auth

package
v0.0.0-...-b8330c8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminUserID int32 = -1
	AdminExamID int32 = -1
)

Variables

View Source
var (
	ErrAdminRequired = errors.New("admin privilege required")
	ErrAuthRequired  = errors.New("authentication required")
)

Functions

func CheckAdmin

func CheckAdmin(ctx context.Context) error

func CheckAuthentication

func CheckAuthentication(ctx context.Context) error

func GenerateRandomPasscode

func GenerateRandomPasscode(length int) string

func GetUserID

func GetUserID(ctx context.Context) (int32, error)

Types

type ContextKey

type ContextKey string
const (
	IsAdminContextKey ContextKey = "is-admin"
	UserIDContextKey  ContextKey = "user-id"
	ExamIDContextKey  ContextKey = "exam-id"
)

type Service

type Service interface {
	NewAdminToken(ctx context.Context, passcode string) (*Token, error)
	NewParticipantToken(ctx context.Context, examPassword string, participantCode string) (*Token, error)
}

func NewService

func NewService(logger *logrus.Logger, jwtService jwt.Service, credentialStore Store) (Service, error)

type Store

type Store interface {
	GetAdminPasscode(ctx context.Context) (string, error)
	CheckExamParticipant(ctx context.Context, examPassword string, participantCode string) (int32, int32, error)
}

func NewSQLiteStore

func NewSQLiteStore(logger *logrus.Logger, dbPool *sqlitex.Pool, passcode string) (Store, error)

type Token

type Token struct {
	AccessToken string
}

Jump to

Keyboard shortcuts

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