随着Core 1.1遵循@ blowdart的建议并实施了自定义中间件:
它的工作方式如下:
这有点适用于2.0,除了如果令牌无效(上面的步骤2)并且从未添加声明我得到"没有指定authenticationScheme,并且没有找到DefaultChallengeScheme."
所以现在我正在读取2.0中的auth更改:
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x
在ASP.NET Core 2.0中我做同样的事情的正确途径是什么?我没有看到做真正的自定义身份验证的示例.
我试图在我的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