我们是 GCP 的新手。我们已经设置了一个 Pub/Sub 队列,该队列具有对外部 Webhook (ASP.NET Web API) 的推送订阅,并启用了身份验证。这为我们在 HTTP post 调用中提供了一个不记名 token 。
我不清楚是否:
- A.我需要首先使用服务帐户
.json
文件请求 token ,并将其与 Pub/Sub 在 Webhook 中发送的不记名 token 进行比较。 - B.我只需要使用
GoogleJsonWebSignature.ValidateAsync(token, settings) 验证来自 pubsub 的 token
?
这两种可能性都有效,我只是不确定安全隐患。选项B很简单,但它真的安全吗?这不可能被篡改吗?
最佳答案
您甚至可以使用 Microsoft 的库来验证 token as explained in this ASP.NET blog post 。鉴于 audience you configured with the push subscription ,使用此代码:
app.UseJwtBearerAuthentication(new JwtBearerOptions()
{
Audience = "", // The audience you configured the token to have
Authority = "https://accounts.google.com",
AutomaticAuthenticate = true
});
关于asp.net-web-api - 如何验证 GCP Pub/sub 推送订阅 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57884599/