Documentation
¶
Index ¶
- Constants
- func CorsConfig(conf *config.Configuration) cors.Config
- func GenerateApplicationToken() (publicForm, privateForm string)
- func GenerateClientToken() (publicForm, privateForm string)
- func GenerateImageName() string
- func GeneratePluginToken() string
- func GetApplication(ctx *gin.Context) *model.Application
- func GetClient(ctx *gin.Context) *model.Client
- func GetUserID(ctx *gin.Context) uint
- func RegisterApplication(ctx *gin.Context, app *model.Application)
- func RegisterClient(ctx *gin.Context, client *model.Client)
- func RegisterUser(ctx *gin.Context, user *model.User)
- func SetCookie(w http.ResponseWriter, token string, maxAge int, secure bool)
- func TryGetUserID(ctx *gin.Context) *uint
- type Auth
- func (a *Auth) Optional(ctx *gin.Context)
- func (a *Auth) RequireAdmin(ctx *gin.Context)
- func (a *Auth) RequireApplicationOrClient(ctx *gin.Context)
- func (a *Auth) RequireApplicationToken(ctx *gin.Context)
- func (a *Auth) RequireClient(ctx *gin.Context)
- func (a *Auth) RequireElevatedClient(ctx *gin.Context)
- type Database
- type EnhancedToken
Constants ¶
const CookieMaxAge = 7 * 24 * 60 * 60
CookieMaxAge is the lifetime of the session cookie in seconds (7 days).
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 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 GetUserID ¶
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 ¶
RegisterClient stores the authenticated client on the gin context.
func RegisterUser ¶
RegisterUser stores the authenticated user on the gin context.
func TryGetUserID ¶
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) RequireAdmin ¶
RequireAdmin requires an elevated client token or basic auth, the user must be an admin.
func (*Auth) RequireApplicationOrClient ¶
RequireAny requires client, application, or basic auth.
func (*Auth) RequireApplicationToken ¶
RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.
func (*Auth) RequireClient ¶
RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied with the request.
func (*Auth) RequireElevatedClient ¶
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