【发布时间】:2017-04-09 23:10:23
【问题描述】:
我有使用 Angularjs 和 .Net Core WebAPI 后端编写的客户端应用程序。用户使用我们获取令牌的 Google 登录进行身份验证。此令牌与必须验证的每个 API 请求一起发送到后端。
是否有中间件或者我如何创建中间件来验证令牌?
【问题讨论】:
标签: .net-core
我有使用 Angularjs 和 .Net Core WebAPI 后端编写的客户端应用程序。用户使用我们获取令牌的 Google 登录进行身份验证。此令牌与必须验证的每个 API 请求一起发送到后端。
是否有中间件或者我如何创建中间件来验证令牌?
【问题讨论】:
标签: .net-core
是的,有:Microsoft.AspNetCore.Authentication.Google
您可以安装:
dotnet 添加包 Microsoft.AspNetCore.Authentication.Google
然后在你的startup.cs中配置中间件:
app.UseGoogleAuthentication(new GoogleOptions()
{
ClientId = Configuration["Authentication:Google:ClientId"],
ClientSecret = Configuration["Authentication:Google:ClientSecret"]
});
我建议您在此处阅读非常有用且易于遵循的 Microsoft ASP.NET 核心社交身份验证指南:
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/
以及此处的 Google 特定演练:
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins
【讨论】: