Azure AD Graph API-将用户添加到应用程序中会收到PlatformNotSupportedException [英] Azure AD Graph API - Adding user to application gets PlatformNotSupportedException

查看:47
本文介绍了Azure AD Graph API-将用户添加到应用程序中会收到PlatformNotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My goal is to add a user to an application in Azure.

我仅将旧的Azure AD Graph API用于此方法,因为较新的Microsoft Graph API当前不支持此功能.

I'm using the old Azure AD Graph API only for this method, because the newer Microsoft Graph API currently doesn't support this feature.

通过排除过程,我发现错误是在尝试通过id获取用户时刚开始时发生的.

By process of elimination, I've found that the error occurs right at the beginning, when trying to get the user by 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);
    }
}

推荐答案

我对旧图使用直接rest httpClient调用.

I use a direct rest httpClient call against the old graph.

我仅将此作为参考发布-请注意网址(1.6)上的显式版本.我还将发布反序列化的对象,这可能与官方对象架构不匹配.

I am only posting this as a reference - notice the explicit version on the url (1.6). I am also posting the object i deserialize into, this may not match the official object schema.

// 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从有效负载转到对象类.请注意,日期不会反序列化为日期.

Due to the rest api string payload I am effectively using the JsonConvert.DeserializeObject to go from payload to object class. Notice that the Dates are not being deserialized as dates.

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; }
}

希望有帮助.

这篇关于Azure AD Graph API-将用户添加到应用程序中会收到PlatformNotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆