c# - Azure AD Graph API - 将用户添加到应用程序获取 PlatformNotSupportedException
问题描述
我的目标是将用户添加到 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);
}
}
解决方案
我对旧图使用直接休息 httpClient 调用。
我只是将其发布为参考 - 请注意 url (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; }
}
希望能帮助到你。
推荐阅读
- python - Do I need celery with asynchronous web frameworks?
- python - 如何将查询集列添加到另一个查询集?
- java - 在实现 RecognitionListener 的 Service 上的空对象引用上的 getApplicationContext()
- javascript - 即使集合中有文档,Model.find({}) 也会返回空
- flutter - 用于多列显示的 Flutter Table
- jquery - 更改幻灯片时暂停 Slick 滑块中的视频
- git - 从 github 上的协作者拉取请求中删除文件
- mysql - 如何在 vb.net 的数据表中按两个文件分组
- bash - 确定分支上是否有要合并的提交
- sql - SQL 列数