webserver

package
v0.0.0-...-e1d3906 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorization

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

Authorization provides functionalities for HTTP session authorization and session lifecycle maintainance.

func NewAuthorization

func NewAuthorization(signingKey []byte, db database.Middleware, cache caching.CacheMiddleware, rlm *ratelimit.RateLimitManager) (auth *Authorization, err error)

NewAuthorization initializes a new Authorization instance using the passed jwtKey, which will be used to sign JWTs, the database driver, cache driver and rate limit manager. If the passed jwtKey is nil or empty, a random key will be generated on initialization.

func (*Authorization) CheckHash

func (auth *Authorization) CheckHash(hash, pass string) bool

CheckHash tries to compare the passed hash string with the passed pass string by using the method and parameters specified in the hash string.

This imlementation supports both the old hash algorithm used in myrunes before batch 1.7.x (bcrypt) and the current implementation argon2id.

func (*Authorization) CheckRequestAuth

func (auth *Authorization) CheckRequestAuth(ctx *routing.Context) error

CheckRequestAuth provides a handler which cancels the current handler stack if no valid session authentication or API token could be identified in the request.

func (*Authorization) CreateAndSetRefreshToken

func (auth *Authorization) CreateAndSetRefreshToken(ctx *routing.Context, uid snowflake.ID, remember bool) (token string, err error)

CreateSession creates a login session for the specified user. This generates a JWT which is signed with the internal jwtKey and then stored as cookie on response.

func (*Authorization) CreateHash

func (auth *Authorization) CreateHash(pass string) (string, error)

CreateHash creates a hash string from the passed pass string containing information about the used algorithm and parameters used to generate the hash together with the actual hash data.

This implementation uses Argon2id hash generation.

func (*Authorization) Login

func (auth *Authorization) Login(ctx *routing.Context) bool

Login provides a handler accepting login credentials as JSON POST body. This is used to authenticate a user and create a login session on successful authentication.

func (*Authorization) Logout

func (auth *Authorization) Logout(ctx *routing.Context) error

Logout provides a handler which removes the session JWT cookie by setting an invalid, expired session cookie.

func (*Authorization) ObtainAccessToken

func (auth *Authorization) ObtainAccessToken(ctx *routing.Context) (string, error)

type Config

type Config struct {
	Addr       string           `json:"addr"`
	PathPrefix string           `json:"pathprefix"`
	TLS        *TLSConfig       `json:"tls"`
	ReCaptcha  *ReCaptchaConfig `json:"recaptcha"`
	PublicAddr string           `json:"publicaddress"`
	EnableCors bool             `json:"enablecors"`
	JWTKey     string           `json:"jwtkey"`
}

Config wraps properties for the HTTP REST API server.

type ReCaptchaConfig

type ReCaptchaConfig struct {
	SiteKey   string `json:"sitekey"`
	SecretKey string `json:"secretkey"`
}

ReCaptchaConfig wraps key and secret for ReCAPTCHA v2.

type TLSConfig

type TLSConfig struct {
	Enabled bool   `json:"enabled"`
	Cert    string `json:"certfile"`
	Key     string `json:"keyfile"`
}

TLSConfig wraps properties for TLS encryption.

type WebServer

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

WebServer provices a HTTP REST API router.

func NewWebServer

func NewWebServer(db database.Middleware, cache caching.CacheMiddleware,
	ms *mailserver.MailServer, avatarAssetsHandler *assets.AvatarHandler,
	config *Config) (ws *WebServer, err error)

NewWebServer initializes a WebServer instance using the specified database driver, cache driver, mail server instance and configuration instance.

func (*WebServer) ListenAndServeBlocking

func (ws *WebServer) ListenAndServeBlocking() error

ListenAndServeBLocing starts the web servers listen and serving lifecycle which blocks the current goroutine.

Jump to

Keyboard shortcuts

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