auth

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: CC-BY-4.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CookieMaxAge = 7 * 24 * 60 * 60

CookieMaxAge is the lifetime of the session cookie in seconds (7 days).

View Source
const CookieName = "gotify-client-token"

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() (publicForm, privateForm string)

GenerateApplicationToken generates an application token.

func GenerateClientToken

func GenerateClientToken() (publicForm, privateForm string)

GenerateClientToken generates a client token.

func GenerateImageName

func GenerateImageName() string

GenerateImageName generates an image name.

func GeneratePluginToken

func GeneratePluginToken() string

GeneratePluginToken generates a plugin token.

func GetApplication

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

GetApplication returns the authenticated application or nil if no application was registered.

func GetClient

func GetClient(ctx *gin.Context) *model.Client

GetClient returns the authenticated client or nil if no client was registered.

func GetUserID

func GetUserID(ctx *gin.Context) uint

GetUserID returns the user id which was previously registered by one of the Register* functions.

func RegisterApplication

func RegisterApplication(ctx *gin.Context, app *model.Application)

RegisterApplication stores the authenticated application on the gin context.

func RegisterClient

func RegisterClient(ctx *gin.Context, client *model.Client)

RegisterClient stores the authenticated client on the gin context.

func RegisterUser

func RegisterUser(ctx *gin.Context, user *model.User)

RegisterUser stores the authenticated user on the gin context.

func SetCookie

func SetCookie(w http.ResponseWriter, token string, maxAge int, secure bool)

func TryGetUserID

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
	SecureCookie     bool
	LocalAuthEnabled bool
	CrossOrigin      *http.CrossOriginProtection
}

Auth is the provider for authentication middleware.

func (*Auth) Optional

func (a *Auth) Optional(ctx *gin.Context)

func (*Auth) RequireAdmin

func (a *Auth) RequireAdmin(ctx *gin.Context)

RequireAdmin requires an elevated client token or basic auth, the user must be an admin.

func (*Auth) RequireApplicationOrClient

func (a *Auth) RequireApplicationOrClient(ctx *gin.Context)

RequireAny requires client, application, or basic auth.

func (*Auth) RequireApplicationToken

func (a *Auth) RequireApplicationToken(ctx *gin.Context)

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

func (*Auth) RequireClient

func (a *Auth) RequireClient(ctx *gin.Context)

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

func (*Auth) RequireElevatedClient

func (a *Auth) RequireElevatedClient(ctx *gin.Context)

RequireElevatedClient requires an elevated client token or basic auth.

type Database

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

The Database interface for encapsulating database access.

type EnhancedToken

type EnhancedToken struct {
	// contains filtered or unexported fields
}

func NewEnhancedToken

func NewEnhancedToken(ident string) *EnhancedToken

NewEnhancedToken creates a new EnhancedToken.

func ParseEnhancedToken

func ParseEnhancedToken(token string) (*EnhancedToken, error)

ParseEnhancedToken parses a string into an EnhancedToken.

func (*EnhancedToken) PublicForm

func (c *EnhancedToken) PublicForm() string

PublicForm returns the a canonicalized representation of the public key.

func (*EnhancedToken) Sign

func (c *EnhancedToken) Sign(timestamp int64) (*EnhancedToken, error)

Sign signs the timestamp with the private key and returns a new EnhancedToken.

func (*EnhancedToken) String

func (c *EnhancedToken) String() string

String marshals the token into a string.

func (*EnhancedToken) ValidateTimestamp

func (c *EnhancedToken) ValidateTimestamp(now int64) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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