Skip to content

Commit

Permalink
RequestURI captures the signature field as well.
Browse files Browse the repository at this point in the history
This in turn results is failure of signature based validation. So what is need is only "/api/resource/action". which is given by ctx.Input.URL()
  • Loading branch information
kbynd authored Sep 4, 2016
1 parent 3f67c62 commit 6d3042f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/apiauth/apiauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func APISecretAuth(f AppIDToAppSecret, timeout int) beego.FilterFunc {
return
}
if ctx.Input.Query("signature") !=
Signature(appsecret, ctx.Input.Method(), ctx.Request.Form, ctx.Input.URI()) {
Signature(appsecret, ctx.Input.Method(), ctx.Request.Form, ctx.Input.URL()) {
ctx.ResponseWriter.WriteHeader(403)
ctx.WriteString("auth failed")
}
}
}

// Signature used to generate signature with the appsecret/method/params/RequestURI
func Signature(appsecret, method string, params url.Values, RequestURI string) (result string) {
func Signature(appsecret, method string, params url.Values, RequestURL string) (result string) {
var query string
pa := make(map[string]string)
for k, v := range params {
Expand All @@ -143,7 +143,7 @@ func Signature(appsecret, method string, params url.Values, RequestURI string) (
query = fmt.Sprintf("%v%v%v", query, vs.Keys[i], vs.Vals[i])
}
}
stringToSign := fmt.Sprintf("%v\n%v\n%v\n", method, query, RequestURI)
stringToSign := fmt.Sprintf("%v\n%v\n%v\n", method, query, RequestURL)

sha256 := sha256.New
hash := hmac.New(sha256, []byte(appsecret))
Expand Down

0 comments on commit 6d3042f

Please sign in to comment.