【问题标题】:HowTo: ADB2C User Groups in Token操作方法:令牌中的 ADB2C 用户组
【发布时间】:2019-08-29 15:13:14
【问题描述】:

我正在运行 ADB2C 租户,并且想知道如何在 ADB2C 身份验证流程中配置和检索身份验证令牌内的用户组。

我能够在我的令牌中配置和接收自定义属性,但我无法配置可能会列出特定组的用户成员资格的组声明。

预期是一个组:{}

【问题讨论】:

  • 更改清单条目和设置 groupMembershipClaims=SecurityGroup 是否可以解决问题?
  • 在 B2C 中,应用程序没有清单。

标签: azure-ad-b2c claims


【解决方案1】:

在 B2C 中,没有将在令牌中返回的组声明,因此您不能在 Azure AD 中遵循相同的方式。

您可以尝试让应用程序手动检索组声明的这些声明并将它们注入到令牌中。

这种方式可以参考Azure AD中的方法:

var authority = $"https://login.microsoftonline.com/{Tenant}";
var graphCca = new ConfidentialClientApplication(GraphClientId, authority, GraphRedirectUri, new ClientCredential(GraphClientSecret), userTokenCache, null);
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };

try
{
    AuthenticationResult authenticationResult = await graphCca.AcquireTokenForClientAsync(scopes);
    string token = authenticationResult.AccessToken;

    using (var client = new HttpClient())
    {
        string requestUrl = $"https://graph.microsoft.com/v1.0/users/{signedInUserID}/memberOf?$select=displayName";

        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

        HttpResponseMessage response = await client.SendAsync(request);
        var responseString = await response.Content.ReadAsStringAsync();

        var json = JObject.Parse(responseString);

        foreach (var group in json["value"])
            notification.AuthenticationTicket.Identity.AddClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, group["displayName"].ToString(), System.Security.Claims.ClaimValueTypes.String, "Graph"));

        //TODO: Handle paging. 
        // https://developer.microsoft.com/en-us/graph/docs/concepts/paging
        // If the user is a member of more than 100 groups, 
        // you'll need to retrieve the next page of results.
    }
} catch (Exception ex)
{
    //TODO: Handle
    throw;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多