【发布时间】:2021-07-26 15:17:29
【问题描述】:
我在使用 IdentityServer 时遇到问题,我正在学习它,所以很有可能我出了点问题。基本上我可以运行应用程序(.net core 5 应用程序和身份服务器 4)
下面是我的 configureServices:
public void ConfigureServices(IServiceCollection 服务) {
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
services.AddDbContext<BMProAppContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
.AddInMemoryApiScopes(deviceclients.GetApiScopes())
.AddInMemoryClients(deviceclients.GetClients())
;
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddIdentityServerJwt()
;
这是我的配置
app.UseRouting();
app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapRazorPages();
当应用程序运行时,它会成功发出一个令牌(我正在使用客户端凭据流)- 然后它会抛出一个错误,如下所示:
Token request success.
失败:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] 执行请求时发生未处理的异常。 System.InvalidOperationException:没有为方案“承载”注册身份验证处理程序。注册的方案有:Identity.Application、Identity.External、Identity.TwoFactorRememberMe、Identity.TwoFactorUserId、idsrv、idsrv.external、IdentityServerJwt、IdentityServerJwtBearer。您是否忘记调用 AddAuthentication().AddSomeAuthHandler? 在 Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext 上下文,字符串方案) 在 Microsoft.AspNetCore.Authorization.Policy.PolicyEvaluator.AuthenticateAsync(AuthorizationPolicy 策略,HttpContext 上下文) 在 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext 上下文) 在 IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext 上下文,IEndpointRouter 路由器,IUserSession 会话,IEventService 事件,IBackChannelLogoutService backChannelLogoutService) 在 IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext 上下文,IAuthenticationSchemeProvider 方案) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) 在 IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) 在 NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext 上下文) 在 NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext 上下文) 在 NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext 上下文)
不确定出了什么问题并已搜索答案,但似乎没有任何帮助:(
任何建议表示赞赏。
【问题讨论】:
标签: identityserver4