mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-25 09:32:43 +00:00
fix(lib/challenge): allow challenges to register HTTP routes (#620)
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- Refactor challenge presentation logic to use a challenge registry
|
- Refactor challenge presentation logic to use a challenge registry
|
||||||
|
- Allow challenge implementations to register HTTP routes
|
||||||
|
|
||||||
## v1.19.1: Jenomis cen Lexentale - Echo 1
|
## v1.19.1: Jenomis cen Lexentale - Echo 1
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ func Methods() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Impl interface {
|
type Impl interface {
|
||||||
Fail(w http.ResponseWriter, r *http.Request) error
|
// Setup registers any additional routes with the Impl for assets or API routes.
|
||||||
|
Setup(mux *http.ServeMux)
|
||||||
|
|
||||||
|
// Issue a new challenge to the user, called by the Anubis.
|
||||||
Issue(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string, ogTags map[string]string) (templ.Component, error)
|
Issue(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string, ogTags map[string]string) (templ.Component, error)
|
||||||
|
|
||||||
|
// Validate a challenge, making sure that it passes muster.
|
||||||
Validate(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string) error
|
Validate(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ type Impl struct {
|
|||||||
Algorithm string
|
Algorithm string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Impl) Fail(w http.ResponseWriter, r *http.Request) error {
|
func (i *Impl) Setup(mux *http.ServeMux) {
|
||||||
return nil
|
/* no implementation required */
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Impl) Issue(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string, ogTags map[string]string) (templ.Component, error) {
|
func (i *Impl) Issue(r *http.Request, lg *slog.Logger, rule *policy.Bot, challenge string, ogTags map[string]string) (templ.Component, error) {
|
||||||
|
|||||||
@@ -151,6 +151,11 @@ func New(opts Options) (*Server, error) {
|
|||||||
registerWithPrefix(anubis.APIPrefix+"test-error", http.HandlerFunc(result.TestError), "GET")
|
registerWithPrefix(anubis.APIPrefix+"test-error", http.HandlerFunc(result.TestError), "GET")
|
||||||
registerWithPrefix("/", http.HandlerFunc(result.maybeReverseProxyOrPage), "")
|
registerWithPrefix("/", http.HandlerFunc(result.maybeReverseProxyOrPage), "")
|
||||||
|
|
||||||
|
for _, implKind := range challenge.Methods() {
|
||||||
|
impl, _ := challenge.Get(implKind)
|
||||||
|
impl.Setup(mux)
|
||||||
|
}
|
||||||
|
|
||||||
result.mux = mux
|
result.mux = mux
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.865
|
// templ: version: v0.3.887
|
||||||
package web
|
package web
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.865
|
// templ: version: v0.3.887
|
||||||
package xess
|
package xess
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|||||||
Reference in New Issue
Block a user