asp.net-web-api - 如何验证 GCP Pub/sub 推送订阅 token ?

标签 asp.net-web-api google-cloud-platform jwt openid-connect google-cloud-pubsub

我们是 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/

相关文章:

javascript - 创建 React App 显示 serviceWorker.js 而不是很多教程显示的 registerServiceWorker

c# - 删除 xmlns :i and xmlns from webapi

c# - ApiController 操作无法从查询字符串中解析数组

python - "' str ' object has no attribute ' 在使用 Google Cloud Storage 和 ScrapingHub 时获取 '"

amazon-web-services - 如何将前端应用程序正确部署到 GCE?

c# - webapi 不会使用 $.param 反序列化字符串数组

python - GCP 身份验证 : RefreshError

amazon-web-services - Cognito 重定向回我的 URL 时找不到刷新 token

JAVA - 使用 JAX-RS 和 JSON Web token 记住用户登录

c# - 来自文件的 .NET Core IssuerSigningKey 用于 JWT 承载身份验证