Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message: The Signature you specified is invalid. #2

Closed
SoloMagic opened this issue Jan 4, 2018 · 6 comments
Closed

Message: The Signature you specified is invalid. #2

SoloMagic opened this issue Jan 4, 2018 · 6 comments

Comments

@SoloMagic
Copy link

SignatureDoesNotMatch The Signature you specified is invalid.
@mozillazg
Copy link
Owner

我这边测试了一下,没问题。麻烦提供可以复现问题的最简代码。

@nEdAy
Copy link

nEdAy commented May 30, 2018

使用的是您的auth.go
authTime := NewAuthTime(defaultAuthExpire)
return c.String(http.StatusOK, newAuthorization(secretID, secretKey, req, authTime))

小程序测试返回403
SignatureDoesNotMatch
The Signature you specified is invalid.

官方wx_sdk生成的authorization 是ok的
var authorization = COS.getAuthorization({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Method: params.Method,
Key: params.Key
});

对比生成的authorization只有q-signature不同,是不是算法实现上有问题
我晚上再仔细看看

@nEdAy
Copy link

nEdAy commented May 30, 2018

小程序部分逻辑我是参照 https://github.com/piscium2010/cos-wx-upload-file
您可以试试

@carsonxu
Copy link

qcloud 出的 demo 有这个:
https://github.com/tencentyun/cos-wx-sdk-v5

@nEdAy
Copy link

nEdAy commented May 30, 2018

官方只有js和php的鉴权服务

@mozillazg
Copy link
Owner

@nEdAy 你可以用你的 bucket、secret_id、secret_key 测试一下上传功能:

export COS_BUCKET_URL=https://<bucket>-<appid>.cos.<region>.myqcloud.com
export COS_SECRETID=xx
export COS_SECRETKEY=xxx
go run _example/object/uploadFile.go

我刚测试了一下没发现问题:

$ go run _example/object/uploadFile.go
5636484
PUT /test%2fuploadFile.go HTTP/1.1
Host: test-1253846586.cos.ap-beijing-1.myqcloud.com
User-Agent: go-cos/0.8.0
Content-Length: 5636484
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxnW4SdORtFPU1We7B5n7LShsjW7WpkZB&q-sign-time=1527723637;1527727237&q-key-time=1527723637;1527727237&q-header-list=content-length&q-url-param-list=&q-signature=b4f3aec6bf7ab01988f67af3d682af45898c3a76
Accept-Encoding: gzip



HTTP/1.1 200 OK
Content-Length: 0
Connection: keep-alive
Content-Type: application/xml
Date: Wed, 30 May 2018 23:40:49 GMT
Etag: "cf6dbd9a4353245fa98707b9a5cc2e63"
Server: tencent-cos
X-Cos-Request-Id: NWIwZjM2NzdfMmZiNTM1MGFfMzczNl8yMjY0MTQ=

初步判断可能是你的 req 中的 url 不是你实际想请求的 cos api url 。
如果你的 req 是小程序客户端发起的 req ,那你需要手动构造一个新的 http.Request,这个新的req 应该包含 cos api 需要的一些信息(url(key), header等)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants