为此,我很难找到一个例子。我的特殊情况如下:
我有一个Angular8 SPA,它通过ADAL从Azure AD获取承载令牌,我需要消耗该令牌并在使用后从AzureAD获取组,因为我们的商店在Azure AD中没有声明组,因此我的API收到了令牌具有“特殊”权限,可以从我们的Azure AD中读取该令牌。最终,我们将使用相同的方法让另一个前端调用此API。我的目标
:我有一个.Net Core C#API,该API将传递给Azure AD令牌,我想验证它是否正确并获取用户所属的组。从那里,我需要根据它们所属的组来授予对各种控制器的访问权限。 (只有3个组有问题,用户,管理员,超级用户)。 我不需要任何用户名或密码或任何登录页面的访问或处理。因此,我已经阅读the documentation here并按照说明保护API的方法,但仍然出现错误,因为这些说明似乎还远远不够,我无法执行此操作。他们在该文档中声明要使用:services.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
但是上面的代码只有在执行以下操作后才能编译(除非我错过了某个地方的库引用):
services.AddAuthentication("AzureAd").AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
或
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
因此,基于我已阅读的大量内容,AD人士在这里说,我应该能够利用Startup.cs消耗承载令牌以允许输入,然后将该令牌发送到AzureAD上的端点以获取我所需要的。我尚未找到涵盖这种情况的任何代码示例,而且我毫无疑问只是我的搜索能力不是那么好,但是鉴于大量矛盾和模糊的信息,我发现这也是该领域的一个雷区。东西。
我有
[Authorize]
public class BaseController: ControllerBase
:然后在startup.cs中,我有
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddAuthentication("AzureAd").AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddDbContext<InternalReportsContext>();
services.AddAutoMapper(typeof(Startup));
}
我最新的错误是:
<div class="titleerror">InvalidOperationException: No authenticationScheme was specified, and there was no
DefaultChallengeScheme found.</div>
<p class="location">Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context,
string scheme, AuthenticationProperties properties)</p>
同样,我还没有找到任何可以详细说明我需要设置什么才能消除该错误的实例。有时我会收到401错误,但大多数情况下都会遇到defaultScheme问题,即使我在AzureAdBearer上设置了默认设置,老实说,我也不记得我使用过的所有配置。
这是我为应用程序创建安全性的首次尝试,我所有其他商店都采用了我可以利用的标准解决方案,而这个地方是采用Orwellian InfoSec策略的FFA slogfest,因此我无法接触60%的开发者博客GitHub也没有使我的个人笔记本电脑正常工作。
因此,如果我错过了涉及该主题的任何
comprehensive
教程,我会很感激[[[extremely]朝着这个方向发展。我在寻找一个可以遵循的示例时遇到了麻烦。我的具体情况如下:我有一个Angular8 SPA,它通过ADAL从Azure AD获取承载令牌,我需要使用......>