微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 oauth2client.service_account 和 google.oauth2 使用私钥签名的区别

如何解决使用 oauth2client.service_account 和 google.oauth2 使用私钥签名的区别

我正在尝试将我的 Google Cloud Storage 网址签名函数更新为 V4。 Google 为此提供了一个模板,我想我会遵循它直到 https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/signed_urls/generate_signed_urls.py#L112

#signer.sign() signs using RSA-SHA256 with PKCS1v15 padding
signature = binascii.hexlify(
    google_credentials.signer.sign(string_to_sign)
).decode()

我目前使用的是 V2 和 oauth2client 库。目前的代码片段是:

    creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_creds)
    signature = binascii.hexlify(creds.sign_blob(string_to_sign)[1]).decode()

但这似乎不起作用,因为我收到签名错误。我试图推理这两种签名方法间的不同之处,但我遇到了麻烦。 https://oauth2client.readthedocs.io/en/latest/_modules/oauth2client/service_account.html#ServiceAccountCredentials.sign_blob

google.oauth2 https://google-auth.readthedocs.io/en/latest/reference/google.auth.crypt.rsa.html

文档中的 RSA 模块中似乎没有文档

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。