auth

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: CC-BY-4.0, MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CorsConfig

func CorsConfig(conf *config.Configuration) cors.Config

CorsConfig generates a config to use in gin cors middleware based on server configuration.

func GenerateApplicationToken

func GenerateApplicationToken() string

GenerateApplicationToken generates an application token.

func GenerateClientToken

func GenerateClientToken() string

GenerateClientToken generates a client token.

func GenerateImageName

func GenerateImageName() string

GenerateImageName generates an image name.

func GenerateNotExistingToken

func GenerateNotExistingToken(generateToken func() string, tokenExists func(token string) bool) string

GenerateNotExistingToken receives a token generation func and a func to check whether the token exists, returns a unique token.

func GeneratePluginToken

func GeneratePluginToken() string

GeneratePluginToken generates a plugin token.

func GetTokenID

func GetTokenID(ctx *gin.Context) string

GetTokenID returns the tokenID.

func GetUserID

func GetUserID(ctx *gin.Context) uint

GetUserID returns the user id which was previously registered by RegisterAuthentication.

func RegisterAuthentication

func RegisterAuthentication(ctx *gin.Context, user *model.User, userID uint, tokenID string)

RegisterAuthentication registers the user id, user and or token.

func TryGetUserID added in v2.1.0

func TryGetUserID(ctx *gin.Context) *uint

TryGetUserID returns the user id or nil if one is not set.

Types

type Auth

type Auth struct {
	DB Database
}

Auth is the provider for authentication middleware.

func (*Auth) Optional added in v2.1.0

func (a *Auth) Optional() gin.HandlerFunc

func (*Auth) RequireAdmin

func (a *Auth) RequireAdmin() gin.HandlerFunc

RequireAdmin returns a gin middleware which requires a client token or basic authentication header to be supplied with the request. Also the authenticated user must be an administrator.

func (*Auth) RequireApplicationToken

func (a *Auth) RequireApplicationToken() gin.HandlerFunc

RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.

func (*Auth) RequireClient

func (a *Auth) RequireClient() gin.HandlerFunc

RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied with the request.

type Database

type Database interface {
	GetApplicationByToken(token string) (*model.Application, error)
	GetClientByToken(token string) (*model.Client, error)
	GetPluginConfByToken(token string) (*model.PluginConf, error)
	GetUserByName(name string) (*model.User, error)
	GetUserByID(id uint) (*model.User, error)
	UpdateClientTokensLastUsed(tokens []string, t *time.Time) error
	UpdateApplicationTokenLastUsed(token string, t *time.Time) error
}

The Database interface for encapsulating database access.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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