【发布时间】:2020-12-11 13:34:53
【问题描述】:
我正在尝试在我的 Cloud Firestore 上执行一些管理任务(上传一些数据等)。我通读了文档here
使用 Google Identity OAuth 2.0 令牌和服务帐户来验证来自您的应用程序的请求,例如数据库管理请求。
这参考了文档here关于如何在生成 JWT 后进行授权 API 调用。我正在努力生成 JWT。
这是我尝试过的:
-
我形成了标题和声明集
{"alg":"RS256","typ":"JWT"}. { "iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com", "scope":"https://www.googleapis.com/auth/prediction", "aud":"https://oauth2.googleapis.com/token", "exp":1328554385, "iat":1328550785 } -
前往https://jwt.io/ 使用 RSA256 生成 JWT。它要求提供公钥和私钥。我知道可以从我在
https://console.cloud.google.com/iam-admin/serviceaccounts下创建的服务帐户以 json 格式生成私钥。但是,我不确定从哪里获得公钥。 jwt.io 不生成 jwt。我只得到“无效签名”。
网络上有很多使用 SDK 或库的示例。但是,我看不到任何有关如何手动生成 JWT(如果可能的话)以将其与 Postman 一起使用的示例。有什么想法吗?
【问题讨论】:
-
我写了一篇文章,展示了如何创建 JWT,对其进行签名,然后交换访问令牌。这也将解释所需的步骤。您可以使用 openssl
openssl rsa -in private.pem -outform PEM -pubout -out public.pem从私钥轻松获取公钥。但是,Google 使用公钥来验证您的私钥签名,您不需要它。 jhanley.com/… 这是创建访问令牌的快捷方式:cloud.google.com/sdk/gcloud/reference/auth/print-access-token -
@JohnHanley 非常感谢。这将我推向了正确的方向。我现在设法生成访问令牌。我会把步骤写在答案中以供将来参考
-
这能回答你的问题吗? Postman - JWT authentication using key file
标签: firebase google-cloud-platform jwt postman