Skip to content

Commit

Permalink
Merge pull request #2 from cwlowder/master
Browse files Browse the repository at this point in the history
Add checks for remoteip and sitekey
  • Loading branch information
kataras authored Sep 19, 2022
2 parents ed700ea + fab7c2a commit 4fe6319
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions hcaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type Client struct {
// and without additional information.
FailureHandler http.Handler

// Optional checks for siteverify
// The user's IP address.
RemoteIP string
// The sitekey you expect to see.
SiteKey string

secret string
}

Expand Down Expand Up @@ -123,12 +129,22 @@ func (c *Client) VerifyToken(tkn string) (response Response) {
return
}

resp, err := c.HTTPClient.PostForm(apiURL,
url.Values{
"secret": {c.secret},
"response": {tkn},
},
)
values := url.Values{
"secret": {c.secret},
"response": {tkn},
}

// Add remoteIP if set
if c.RemoteIP != "" {
values.Add("remoteip", c.RemoteIP)
}

// Add sitekey if set
if c.SiteKey != "" {
values.Add("sitekey", c.SiteKey)
}

resp, err := c.HTTPClient.PostForm(apiURL, values)
if err != nil {
response.ErrorCodes = append(response.ErrorCodes, err.Error())
return
Expand Down

0 comments on commit 4fe6319

Please sign in to comment.