我用google auth创建了一个React应用,它运行正常。现在,我想将Google令牌检查到我的dotnet核心网络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>"));
谁能告诉我们如何使用c#中具有[Authorize]属性的dotnet core API来检查和验证Google令牌?
我的React应用在localhost:3000上运行,API在localhost:5001上
答案 0 :(得分:0)
终于解决了!我按照http://koscielniak.me/post/2016/04/accesing-api-with-token-from-google-identity-provider/
中的定义设置了中间件这适用于api请求中的有效令牌。对于无效的令牌,它不会返回,但对我来说很好...