【问题标题】:IdentityServer3 with aspnet core client带有 aspnet 核心客户端的 IdentityServer3
【发布时间】:2016-10-10 08:18:20
【问题描述】:

我已经设置了 IdentityServer3,并且可以使用存储在 aspnetIdentity 数据库中的用户名和密码成功地进行身份验证。问题出在客户端 MVC 应用程序端。从身份服务器应用程序接收到授权码后,它会抛出以下异常:

处理请求时发生未处理的异常。

InvalidOperationException:未配置身份验证处理程序 处理方案:cookies

我的Startup.cs 看起来像这样:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
    app.UseBrowserLink();
}
else
{
    app.UseExceptionHandler("/Home/Error");
}
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "Cookies",
    AutomaticAuthenticate = true,
    AutomaticChallenge = true

});
var secret = Configuration["Secrets:SharedSecret"];//.ToSha256();
var connectOptions = new OpenIdConnectOptions
{
    AutomaticChallenge = true,
    AutomaticAuthenticate=true,
    AuthenticationScheme = "oidc",
    SignInScheme = "cookies",
    Authority = "http://localhost:4889/core/",
    PostLogoutRedirectUri = "http://localhost:5059/",
    CallbackPath = "/home/index",
    ClientSecret = secret,
    RequireHttpsMetadata = false,
    ClientId = "communicator",
    DisplayName = "Communicator",
    ResponseType = "code id_token",
    GetClaimsFromUserInfoEndpoint = true,
    SaveTokens = true,
    Events = new OpenIdConnectEvents()
    {
        OnUserInformationReceived = async y =>
        {

            var identity = y.Ticket.Principal.Identity as ClaimsIdentity;
            var subject = identity.Claims.FirstOrDefault(z => z.Type == "sub");
            // Do something with subject like lookup in local users DB.
            var newIdentity = new ClaimsIdentity( y.Ticket.AuthenticationScheme,"given_name","role");
            // Do some stuff to `newIdentity` like adding claims.
            // Create a new ticket with `newIdentity`.
                //Ticket = new Ticket(new ClaimsPrincipal(newIdentity),
                //y.Ticket.Properties,
                //y.Ticket.AuthenticationScheme);

            await Task.FromResult(0);
        },
        OnAuthorizationCodeReceived= async c=>
        {
            var identity = c.Ticket.Principal.Identity as ClaimsIdentity;
            var subject =   identity.Claims.FirstOrDefault(z => z.Type == "sub");
            await Task.FromResult(0);
        }

    }
};
connectOptions.Scope.Clear();
connectOptions.Scope.Add("openid");
connectOptions.Scope.Add("profile");
connectOptions.Scope.Add("roles");
connectOptions.Scope.Add("smsapi");
app.UseOpenIdConnectAuthentication(connectOptions);

【问题讨论】:

  • AuthenticationSchemeCookieAuthenticationOptions 中是否区分大小写?

标签: c# asp.net-core asp.net-core-mvc openid-connect identityserver3


【解决方案1】:

您的配置中似乎存在区分大小写的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 2018-04-07
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 2018-02-28
    相关资源
    最近更新 更多