auth

package
v0.0.0-...-1a9902f Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: AGPL-3.0, AGPL-3.0-or-later Imports: 16 Imported by: 0

Documentation

Overview

Package auth determines and asserts client permissions to access and modify server resources.

Index

Constants

View Source
const (
	// Name of cookie that holds the captcha session
	CaptchaCookie = "captcha_session"
)

Variables

View Source
var (
	ErrInvalidToken = common.ErrInvalidInput("invalid token")
)

Functions

func BcryptCompare

func BcryptCompare(password string, hash []byte) error

BcryptCompare compares a bcrypt hash with a user-supplied string

func BcryptHash

func BcryptHash(password string, rounds int) ([]byte, error)

BcryptHash generates a bcrypt hash from the passed string

func CaptchaService

func CaptchaService(board string) *captchouli.Service

Retrieve captcha service for specific board

func DisconnectByBoardAndIP

func DisconnectByBoardAndIP(ip, board string)

DisconnectByBoardAndIP disconnects all banned websocket clients matching IP from board. /all/ board disconnects all clients globally.

func GetIP

func GetIP(r *http.Request) (string, error)

GetIP extracts the IP of a request, honouring reverse proxies, if set

func IsBoard

func IsBoard(board string) bool

IsBoard confirms the string is a valid board

func IsNonMetaBoard

func IsNonMetaBoard(b string) bool

IsNonMetaBoard returns whether a valid board is a classic board and not some other path that emulates a board

func LoadCaptchaServices

func LoadCaptchaServices() (err error)

Initialize captcha services, if not already running, and launch a service for the configured tags with optional additional services for select boards. This function blocks until all services are initialized.

func RandomID

func RandomID(length int) (string, error)

RandomID generates a randomID of base64 characters of desired byte length

Types

type Ban

type Ban struct {
	IP, Board string
}

Ban holds an entry of an IP being banned from a board

type BanRecord

type BanRecord struct {
	Ban
	ForPost          uint64
	Reason, By, Type string
	Expires          time.Time
}

BanRecord stores information about a specific ban

type Base64Token

type Base64Token [64]byte

64 byte token that JSON/text en/decodes to a raw URL-safe encoding base64 string

func NewBase64Token

func NewBase64Token() (b Base64Token, err error)

Create new Base64Token populated by cryptographically secure random data

func (*Base64Token) EnsureCookie

func (b *Base64Token) EnsureCookie(
	w http.ResponseWriter,
	r *http.Request,
) (err error)

Ensure client has a "captcha_session" cookie. If yes, read it into b. If not, generate new one and set it on the client.

For less disruptive toggling of captchas on and off, best always ensure this cookie exists on the client.

func (Base64Token) MarshalText

func (b Base64Token) MarshalText() ([]byte, error)

func (*Base64Token) UnmarshalText

func (b *Base64Token) UnmarshalText(buf []byte) error

type Captcha

type Captcha struct {
	CaptchaID CaptchaID       `json:"id"`
	Solution  CaptchaSolution `json:"solution"`
}

Captcha contains the ID and solution of a captcha-protected request

func CreateTestCaptcha

func CreateTestCaptcha() (c Captcha, err error)

Create a sample captcha for testing purposes and return it with its solution

func (*Captcha) FromRequest

func (c *Captcha) FromRequest(r *http.Request)

Zeroes c on no captcha in request It is up to the caller to decide, if the returned error should or should not be ignored.

type CaptchaID

type CaptchaID [64]byte

64 byte ID that JSON en/decodes to a base64 string

func (*CaptchaID) FromRequest

func (b *CaptchaID) FromRequest(r *http.Request)

func (CaptchaID) MarshalJSON

func (b CaptchaID) MarshalJSON() ([]byte, error)

func (*CaptchaID) UnmarshalJSON

func (b *CaptchaID) UnmarshalJSON(buf []byte) (err error)

type CaptchaSolution

type CaptchaSolution []byte

Solution to a captcha with special JSON en/decoding

func (CaptchaSolution) MarshalJSON

func (s CaptchaSolution) MarshalJSON() ([]byte, error)

func (*CaptchaSolution) UnmarshalJSON

func (s *CaptchaSolution) UnmarshalJSON(buf []byte) (err error)

type ModLogEntry

type ModLogEntry struct {
	common.ModerationEntry
	ID      uint64    `json:"id"`
	Created time.Time `json:"created"`
	Board   string    `json:"board"`
}

ModLogEntry is a single entry in the moderation log

type Report

type Report struct {
	ID, Target    uint64
	Created       time.Time
	Board, Reason string
}

Report contains data of a reported post

type SessionCreds

type SessionCreds struct {
	UserID, Session string
}

SessionCreds is embed in every request that needs logged in authentication

Jump to

Keyboard shortcuts

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