Documentation ¶
Overview ¶
Package auth determines and asserts client permissions to access and modify server resources.
Index ¶
- Constants
- Variables
- func BcryptCompare(password string, hash []byte) error
- func BcryptHash(password string, rounds int) ([]byte, error)
- func CaptchaService(board string) *captchouli.Service
- func DisconnectByBoardAndIP(ip, board string)
- func GetIP(r *http.Request) (string, error)
- func IsBoard(board string) bool
- func IsNonMetaBoard(b string) bool
- func LoadCaptchaServices() (err error)
- func RandomID(length int) (string, error)
- type Ban
- type BanRecord
- type Base64Token
- type Captcha
- type CaptchaID
- type CaptchaSolution
- type ModLogEntry
- type Report
- type SessionCreds
Constants ¶
const (
// Name of cookie that holds the captcha session
CaptchaCookie = "captcha_session"
)
Variables ¶
var (
ErrInvalidToken = common.ErrInvalidInput("invalid token")
)
Functions ¶
func BcryptCompare ¶
BcryptCompare compares a bcrypt hash with a user-supplied string
func BcryptHash ¶
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 IsNonMetaBoard ¶
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.
Types ¶
type Ban ¶
type Ban struct {
IP, Board string
}
Ban holds an entry of an IP being banned from a board
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 ¶
Create a sample captcha for testing purposes and return it with its solution
func (*Captcha) FromRequest ¶
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 (CaptchaID) MarshalJSON ¶
func (*CaptchaID) UnmarshalJSON ¶
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 SessionCreds ¶
type SessionCreds struct {
UserID, Session string
}
SessionCreds is embed in every request that needs logged in authentication