【问题标题】:Google Authentication with react and dotnet core web API使用 React 和 dotnet 核心 Web API 进行 Google 身份验证
【发布时间】:2018-07-24 04:27:25
【问题描述】:

我使用谷歌身份验证创建了一个反应应用程序,它工作正常。现在我想检查 google 令牌到我的 dotnet 核心 Web API 并验证它。

我用 AddGoogle 方法尝试了 services.AddAuthentication,但它不起作用。

我也厌倦了中间件https://github.com/khellang/Middleware/tree/master/src/Authentication.JwtBearer.Google。但这并不奏效

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(x => x.UseGoogle(
    clientId: "<google-client-id>",
    hostedDomain: "<optional-g-suite-domain>"));

谁能告诉我们如何使用带有 [Authorize] 属性的 c# 中的 dotnet core API 检查和验证 google 令牌?

我的 React 应用在 localhost:3000 上运行,API 在 localhost:5001 上

【问题讨论】:

  • 我也有同样的问题。我也有一个带有工作客户端谷歌身份验证的反应应用程序。我现在想保护一个具有授权属性的网络 API,并使用 UI 中相关的谷歌身份验证令牌。
  • 我也遇到了同样的问题,还没找到解决办法,有人找到解决办法了吗?

标签: c# authentication .net-core google-oauth


【解决方案1】:

终于解决了!我按照http://koscielniak.me/post/2016/04/accesing-api-with-token-from-google-identity-provider/中的定义设置了中间件

这适用于 api 请求中的有效令牌。对于无效的令牌,它不会返回,但对我来说很好......

【讨论】:

    猜你喜欢
    • 2020-08-17
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2018-07-18
    • 2020-07-26
    • 2018-02-27
    相关资源
    最近更新 更多