Documentation
¶
Overview ¶
Package xep0077 implements XEP-0077: In-Band Registration.
Index ¶
- Constants
- type CaptchaConfig
- type CaptchaVerifier
- type Config
- type Register
- func (r *Register) AccountFeatures(_ context.Context) ([]string, error)
- func (r *Register) MatchesNamespace(namespace string, serverTarget bool) bool
- func (r *Register) Name() string
- func (r *Register) ProcessIQ(ctx context.Context, iq *stravaganza.IQ) error
- func (r *Register) ServerFeatures(_ context.Context) ([]string, error)
- func (r *Register) Start(_ context.Context) error
- func (r *Register) Stop(_ context.Context) error
- func (r *Register) StreamFeature(_ context.Context, _ string) (stravaganza.Element, error)
- type TokenValidator
Constants ¶
const ( // ModuleName represents in-band registration module name. ModuleName = "ibr" // XEPNumber represents in-band registration XEP number. XEPNumber = "0077" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptchaConfig ¶ added in v0.7.0
type CaptchaConfig struct {
// Enabled turns the challenge on. While false the registration form stays
// the plain XEP-0077 form, whatever the other fields say.
Enabled bool `fig:"enabled"`
// Domains lists the domains that require a challenge. Empty = all domains
// this server hosts.
Domains []string `fig:"domains"`
// ExcludeDomains lists domains that never require a challenge. It is
// applied after Domains.
ExcludeDomains []string `fig:"exclude_domains"`
// ChallengeLength is the number of characters drawn into the image
// (default: 5). Keep it between 4 and 8: shorter is guessable, longer is
// unreadable once the image is warped.
ChallengeLength int `fig:"challenge_length" default:"5"`
// TTL is how long an issued challenge stays valid (default: 10m).
TTL time.Duration `fig:"ttl" default:"10m"`
// MaxAttempts is how often one challenge may be answered before it is
// burnt (default: 3).
MaxAttempts int `fig:"max_attempts" default:"3"`
// FallbackURL points at a web page that shows an equivalent challenge, for
// clients that cannot render the inline image. Empty = no such field is
// advertised, because advertising a URL that does not exist would be a
// lie in the form.
FallbackURL string `fig:"fallback_url"`
// HashcashBits is the number of bits for the SHA-256 Hashcash challenge
// offered alongside the OCR image (XEP-0158 §6.2, default: 20). Clients
// that cannot render the image can solve the Hashcash instead.
HashcashBits int `fig:"hashcash_bits" default:"20"`
}
CaptchaConfig configures the XEP-0158 OCR challenge that new registrations must answer.
The switch is per domain, not per server: one Zerta instance serves every domain in its `hosts:` list, and an operator usually wants the challenge on the domains that accept public sign-ups while leaving an internal domain alone. Domains matches by name, ExcludeDomains wins over it, and an empty Domains list means "every hosted domain".
type CaptchaVerifier ¶ added in v0.7.0
type CaptchaVerifier interface {
New() (*captcha.Challenge, error)
Verify(id, answer string) captcha.Result
}
CaptchaVerifier issues and verifies XEP-0158 OCR challenges. It is an interface so the module can be tested without rendering images; *captcha.Store is the production implementation.
type Config ¶
type Config struct {
// AllowChange allows users to change their password.
AllowChange bool `fig:"allow_change"`
// AllowRemove allows users to remove their account.
AllowRemove bool `fig:"allow_remove"`
// InviteOnly requires a valid invitation token (XEP-0401) for new registrations.
InviteOnly bool `fig:"invite_only"`
// RegistrationRateLimit is max registrations per IP per window (default: 3).
RegistrationRateLimit int `fig:"registration_rate_limit" default:"3"`
// RegistrationRateWindow is the time window for rate limiting (default: 1h).
RegistrationRateWindow time.Duration `fig:"registration_rate_window" default:"1h"`
// WatchJIDs is a list of JIDs to notify on new registrations.
WatchJIDs []string `fig:"watch_jids"`
// WelcomeMessage is sent to newly registered users. Empty = disabled.
WelcomeMessage string `fig:"welcome_message"`
// Captcha configures the XEP-0158 OCR challenge for new registrations.
Captcha CaptchaConfig `fig:"captcha"`
}
Config contains in-band registration module configuration.
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register represents an in-band registration (XEP-0077) module type.
func New ¶
func New( cfg Config, router router.Router, rep repository.Repository, peppers *pepper.Keys, tokenValidator TokenValidator, captchaVerifier CaptchaVerifier, bobCache *bobcache.Cache, logger kitlog.Logger, ) *Register
New returns a new initialized Register instance. tokenValidator may be nil; if set and cfg.InviteOnly is true, new registrations require a valid XEP-0401 invitation token.
captchaVerifier may be nil: the challenge is then unavailable and only the plain form is served, no matter what cfg.Captcha says. A configured-but- unusable CAPTCHA must never degrade into an unprotected form, so callers that enable cfg.Captcha.Enabled have to pass a verifier.
func (*Register) AccountFeatures ¶
AccountFeatures returns module account disco features.
func (*Register) MatchesNamespace ¶
MatchesNamespace tells whether namespace matches this module.
func (*Register) ServerFeatures ¶
ServerFeatures returns module server disco features.
func (*Register) StreamFeature ¶
StreamFeature returns module stream feature.