0
我已設置IdentityServer3,並且可以使用存儲在aspnetIdentity數據庫上的用戶名和密碼成功進行身份驗證。問題出在客戶端MVC應用程序端。從身份服務器應用程序接收到授權碼後,它會引發以下異常:IdentityServer3與aspnet核心客戶端
處理請求時發生未處理的異常。
InvalidOperationException異常:無認證處理程序被配置爲 處理方案:餅乾
我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);
'CookieAuthenticationOptions'中'AuthenticationScheme'是否區分大小寫? –