authentication

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateApplicationToken

func GenerateApplicationToken(compat bool) string

GenerateApplicationToken generates a token for an application.

func GenerateNotExistingToken

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

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

func GetApplication

func GetApplication(ctx *gin.Context) *model.Application

GetApplication returns the application which was previously registered by the authentication middleware.

func GetUser

func GetUser(ctx *gin.Context) *model.User

GetUser returns the user which was previously registered by the authentication middleware.

Types

type Authenticator

type Authenticator struct {
	DB Database
}

Authenticator is the provider for authentication middleware.

func (*Authenticator) RequireAdmin

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

RequireAdmin returns a Gin middleware which requires valid admin credentials to be supplied with the request.

func (*Authenticator) RequireApplicationToken

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

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

func (*Authenticator) RequireUser

func (a *Authenticator) RequireUser() gin.HandlerFunc

RequireUser returns a Gin middleware which requires valid user credentials to be supplied with the request.

type Database

type Database interface {
	GetApplicationByToken(token string) (*model.Application, error)
	GetUserByName(name string) (*model.User, 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