【发布时间】:2020-05-01 05:03:45
【问题描述】:
我正在开发用户通过 Steam 登录的 ASP.NET Core Web API。
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = SteamAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddSteam(options =>
{
options.Events.OnAuthenticated = ctx => // Create user
});
// ...
}
目前我正在使用 cookie,并且身份验证和授权都可以正常工作。但我想使用 JWT。如果我简单地将AddCookie 替换为AddJwtBearer 我会得到以下异常:The authentication handler registered for scheme 'Bearer' is 'JwtBearerHandler' which cannot be used for SignInAsync。
在github issue 中,它说我需要一个 OpenID Connect 服务器,但我不明白为什么,因为如果我想自己编写 JWT 逻辑,我可以在 open id 回调中生成令牌并返回它给用户。还是我错过了什么?
【问题讨论】:
标签: asp.net-core .net-core openid-connect aspnet-contrib