我试图在我的ASP.NET Core 2.0 web api中集成google身份验证,我无法弄清楚如何让它工作.
我在我的Startup.cs中有这个代码ConfigureServices:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddDefaultTokenProviders();
services.AddAuthentication()
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
});
Run Code Online (Sandbox Code Playgroud)
这个在Configure(IApplicationBuilder app, IHostingEnvironment env):
app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)
当我导航到Authorized端点时,结果是302 Found因为它可能是重定向到某个登录端点(我从未创建过).如何阻止重定向,只是让API期望一个令牌,401如果没有提供令牌,则返回一个令牌?
google-api google-authentication oauth-2.0 asp.net-core asp.net-core-2.0