Azure AD Graph API - 将用户添加到应用程序会获得PlatformNotSupportedException

问题描述 投票:0回答:1

我的目标是将用户添加到Azure中的应用程序。

我只使用旧的Azure AD Graph API用于此方法,因为较新的Microsoft Graph API目前不支持此功能。

通过消除过程,我发现在尝试通过id获取用户时,错误发生在开头。

我得到的错误是;

System.InvalidOperationException: An error occurred while processing this request. ---> System.PlatformNotSupportedException: Secure binary serialization is not supported on this platform.

我的方法代码;

public async Task AddUserToService(string userId)
{
    try
    {
        var user = await activeDirectoryClient.Users.GetByObjectId(userId).ExecuteAsync() as User;

        var appRoleAssignment = new AppRoleAssignment()
        {
            ResourceId = Guid.Parse(applicationId),
            PrincipalId = Guid.Parse(userId),
            Id = Guid.Parse(roleId)
        };

        user.AppRoleAssignments.Add(appRoleAssignment);
        await user.UpdateAsync();
    } catch (Exception e)
    {
        _logger.Log(Microsoft.Extensions.Logging.LogLevel.Error, "Error occurred during retrieval; " + e);
    }
}
c# azure-active-directory azure-ad-graph-api
1个回答
0
投票

我使用针对旧图的直接休息httpClient调用。

我只是将其作为参考发布 - 请注意网址(1.6)上的显式版本。我也发布了反序列化的对象,这可能与官方对象模式不匹配。

// OLD Graph End point    //  like ... https://graph.windows.net/{tenant-id}/users/{id}/appRoleAssignments?api-version=1.6
   urlUserInviteToUse = "https://graph.windows.net/" + m_CfgHlp.TenIdInB2C + "/" + ObjFamilyName + "/" + DirObjIdToGet + "/" + ObjFunctionCall + "?api-version=1.6";

由于其余的api字符串有效负载,我有效地使用JsonConvert.DeserializeObject从有效负载转到对象类。请注意,日期不会被反序列化为日期。

public class AppRoleAssignmentsRoot
{
    public string odatametadata { get; set; }
    public AppRoleAssignment[] value { get; set; }
}

public class AppRoleAssignment
{
    public string odatatype { get; set; }
    public string objectType { get; set; }
    public string objectId { get; set; }
    public object deletionTimestamp { get; set; }
    public object creationTimestamp { get; set; }
    public string id { get; set; }
    public string principalDisplayName { get; set; }
    public string principalId { get; set; }
    public string principalType { get; set; }
    public string resourceDisplayName { get; set; }
    public string resourceId { get; set; }
}

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.