forked from go-packages/paypal
Merge pull request #231 from madprogramer/master
Potential fix for Issue 230
This commit is contained in:
commit
bf9103c70e
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -89,13 +90,15 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque
|
||||||
TransmissionSig string `json:"transmission_sig,omitempty"`
|
TransmissionSig string `json:"transmission_sig,omitempty"`
|
||||||
TransmissionTime string `json:"transmission_time,omitempty"`
|
TransmissionTime string `json:"transmission_time,omitempty"`
|
||||||
WebhookID string `json:"webhook_id,omitempty"`
|
WebhookID string `json:"webhook_id,omitempty"`
|
||||||
Event json.RawMessage `json:"webhook_event"`
|
Event json.RawMessage `json:"webhook_event,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the content
|
// Read the content
|
||||||
var bodyBytes []byte
|
var bodyBytes []byte
|
||||||
if httpReq.Body != nil {
|
if httpReq.Body != nil {
|
||||||
bodyBytes, _ = ioutil.ReadAll(httpReq.Body)
|
bodyBytes, _ = ioutil.ReadAll(httpReq.Body)
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("Cannot verify webhook for HTTP Request with empty body.")
|
||||||
}
|
}
|
||||||
// Restore the io.ReadCloser to its original state
|
// Restore the io.ReadCloser to its original state
|
||||||
httpReq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
httpReq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user