@@ -15,14 +15,19 @@ var (
15
15
ErrInvalidSignature = errors .New ("invalid signature" )
16
16
)
17
17
18
+ type ParseOption struct {
19
+ SkipSignatureValidation func () bool
20
+ }
21
+
18
22
// ParseRequest func
19
- func ParseRequest (channelSecret string , r * http.Request ) (* CallbackRequest , error ) {
23
+ func ParseRequestWithOption (channelSecret string , r * http.Request , opt * ParseOption ) (* CallbackRequest , error ) {
20
24
defer func () { _ = r .Body .Close () }()
21
25
body , err := io .ReadAll (r .Body )
22
26
if err != nil {
23
27
return nil , err
24
28
}
25
- if ! ValidateSignature (channelSecret , r .Header .Get ("x-line-signature" ), body ) {
29
+ skip := opt != nil && opt .SkipSignatureValidation != nil && opt .SkipSignatureValidation ()
30
+ if ! skip && ! ValidateSignature (channelSecret , r .Header .Get ("x-line-signature" ), body ) {
26
31
return nil , ErrInvalidSignature
27
32
}
28
33
@@ -33,6 +38,10 @@ func ParseRequest(channelSecret string, r *http.Request) (*CallbackRequest, erro
33
38
return & cb , nil
34
39
}
35
40
41
+ func ParseRequest (channelSecret string , r * http.Request ) (* CallbackRequest , error ) {
42
+ return ParseRequestWithOption (channelSecret , r , nil )
43
+ }
44
+
36
45
func ValidateSignature (channelSecret , signature string , body []byte ) bool {
37
46
decoded , err := base64 .StdEncoding .DecodeString (signature )
38
47
if err != nil {
0 commit comments