gpt4 book ai didi

asp.net-mvc - OpenIdConnect 是唯一在 Azure Active Directory 中实现授权的中间件

转载 作者:行者123 更新时间:2023-12-03 04:33:35 26 4
gpt4 key购买 nike

我们正在尝试使用 Azure Active Directory 为我们的网站设置身份验证和授权。

我们首先使用 WS-Federation OWIN 中间件进行身份验证,效果非常好(根据 this sample )。

然后,我们尝试插入授权并陷入困境 - Azure Active Directory 中基于角色和组的设置都需要如下内容:

AuthorizationCodeReceived = context =>
{
// Get Access Token for User's Directory
string userObjectId = context.AuthenticationTicket.Identity.FindFirst(Globals.ObjectIdClaimType).Value;
string tenantId = context.AuthenticationTicket.Identity.FindFirst(Globals.TenantIdClaimType).Value;
ClientCredential credential = new ClientCredential(ConfigHelper.ClientId, ConfigHelper.AppKey);
AuthenticationContext authContext = new AuthenticationContext(
String.Format(CultureInfo.InvariantCulture, ConfigHelper.AadInstance, tenantId),
new TokenDbCache(userObjectId));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
context.Code,
new Uri(
string.Format(
URI_MANGLER,
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Authority,
System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath)),
credential,
ConfigHelper.GraphResourceId);

return Task.FromResult(0);
}

使用 WS-Federation,上下文中不存在“代码”字段之类的内容。

在 AAD 中设置租户,添加应用程序并更新 list 以具有多个角色。用户被分配到应用程序并被赋予特定的角色。

因此,我们将所有内容都移至 OpenId,但问题是:这是处理此类要求的最愚蠢的方法吗?

最佳答案

即使使用 WS-Federation,您也绝对可以获得角色并针对 [Authorize] 使用它们。只需按照 https://github.com/AzureADSamples/WebApp-RoleClaims-DotNet 自述文件中的说明进行操作即可用于在 azure AD 中打开应用程序的角色创建和发射。此外,您必须确保类型 http://schemas.microsoft.com/ws/2008/06/identity/claims/role 的声明用作应用程序中的角色类型。无论如何,这应该是默认值。

关于asp.net-mvc - OpenIdConnect 是唯一在 Azure Active Directory 中实现授权的中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com