mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 17:59:24 -04:00

* feat: implement challenge method registry This paves the way for implementing a no-js check method (#95) by making the challenge providers more generic. Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(lib/challenge): rename proof-of-work package to proofofwork Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(lib): make validated challenges a CounterVec Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(lib): annotate jwts with challenge method Signed-off-by: Xe Iaso <me@xeiaso.net> * test(lib/challenge/proofofwork): implement tests Signed-off-by: Xe Iaso <me@xeiaso.net> * test(lib): add smoke tests for known good and known bad config files Signed-off-by: Xe Iaso <me@xeiaso.net> * docs: update CHANGELOG Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(lib): use challenge.Impl#Issue when issuing challenges Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
38 lines
784 B
Go
38 lines
784 B
Go
package challenge
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
var (
|
|
ErrFailed = errors.New("challenge: user failed challenge")
|
|
ErrMissingField = errors.New("challenge: missing field")
|
|
ErrInvalidFormat = errors.New("challenge: field has invalid format")
|
|
)
|
|
|
|
func NewError(verb, publicReason string, privateReason error) *Error {
|
|
return &Error{
|
|
Verb: verb,
|
|
PublicReason: publicReason,
|
|
PrivateReason: privateReason,
|
|
StatusCode: http.StatusForbidden,
|
|
}
|
|
}
|
|
|
|
type Error struct {
|
|
Verb string
|
|
PublicReason string
|
|
PrivateReason error
|
|
StatusCode int
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
return fmt.Sprintf("challenge: error when processing challenge: %s: %v", e.Verb, e.PrivateReason)
|
|
}
|
|
|
|
func (e *Error) Unwrap() error {
|
|
return e.PrivateReason
|
|
}
|