forked from motiv-labs/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifier.go
40 lines (32 loc) · 920 Bytes
/
verifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package provider
import (
"net/http"
"github.com/pkg/errors"
)
// Verifier contains the methods for verification of providers
type Verifier interface {
Verify(r *http.Request, httpClient *http.Client) (bool, error)
}
// VerifierBasket acts as a collection of verifier
type VerifierBasket struct {
verifiers []Verifier
}
//NewVerifierBasket creates a new instace of VerifierBasket
func NewVerifierBasket(verifiers ...Verifier) *VerifierBasket {
return &VerifierBasket{verifiers: verifiers}
}
// Verify checks is the provider is valid
func (vb *VerifierBasket) Verify(r *http.Request, httpClient *http.Client) (bool, error) {
var wrappedErrors error
for _, verifier := range vb.verifiers {
verified, err := verifier.Verify(r, httpClient)
if err != nil {
wrappedErrors = errors.Wrap(err, "verification failed")
continue
}
if verified {
return true, nil
}
}
return false, wrappedErrors
}