繁体   English   中英

使用 NoSQL 数据库的 ASP.NET Core 身份验证

[英]ASP.NET Core Authentication with NoSQL database

ASP.NET Core 3.0 有很多变化,我不知道从哪里开始。 我的目标是使用 MongoDB 而不是 SQL Server (EF) 来存储用户和角色。 我已经阅读了很多答案,但特别是我正在查看https://markjohnson.io/articles/asp-net-core-identity-without-entity-framework/ 我的 Web 应用程序基本上是从带有 Angular 的 ASP.NET Core Web 应用程序生成的。 我现在想向 Web 应用程序添加授权。 我在 Angular 中添加了拦截器,但是当我开始调试这个应用程序时,堆栈返回 500:

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IClientRequestParametersProvider' while attempting to activate 'BSoftSolutions.Controllers.OidcConfigurationController'.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at lambda_method(Closure , IServiceProvider , Object[] )
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS
=======
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: close
Host: localhost:44342
Referer: https://localhost:44342/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
sec-fetch-site: same-origin
sec-fetch-mode: cors

我有一个 OidcConfigurationController 有一个方法

[HttpGet("_configuration/{clientId}")]
public IActionResult GetClientRequestParameters([FromRoute]string clientId)
{
    var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId);
    return Ok(parameters);
}

不过好像没这么叫。 这似乎是异常的来源。 我不确定 GetClientParameters 应该返回什么以及它如何计入整个授权方案。 最后我所追求的是强制授权过程使用 MongoDB 而不是 MS SQL。

我知道这是重复的。 但我不知道哪些适用于 Core 3.0 和 Angular,哪些不适用?

最新的 3.1 版本只需要你在service/controller层注入IClientRequestParametersProvider (Microsoft.AspNetCore.ApiAuthorization.IdentityServer)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM