【问题标题】:Azure AD Graph: Secure binary serialization is not supported on this platformAzure AD Graph:此平台不支持安全二进制序列化
【发布时间】:2019-04-12 02:06:10
【问题描述】:

我们在 .NET Core 2.1 上运行,有时在运行以下查询时会收到异常“此平台不支持安全二进制序列化”:

await _adClient.Users[userId].AppRoleAssignments.ExecuteAsync();

重新执行查询通常有效,因此满足某些条件,即在后续请求中未尝试(或成功?)二进制序列化?也就是说,如果我重新启动服务,它通常也会处理第一个请求。

我们正在使用旧版 AD Graph 客户端,因为 1) Microsoft Graph 客户端尚不完全支持 AppRoleAssignments 以及 2) 支持的是测试版的一部分,不建议用于生产。

下面的完整调用堆栈:

System.Data.Services.Client.BaseAsyncResult.EndExecute<T>(object source, string method, IAsyncResult asyncResult)
System.Data.Services.Client.QueryResult.EndExecuteQuery<TElement>(object source, string method, IAsyncResult asyncResult)
System.Data.Services.Client.DataServiceRequest.EndExecute<TElement>(object source, DataServiceContext context, string method, IAsyncResult asyncResult)
System.Data.Services.Client.DataServiceQuery<TElement>.EndExecute(IAsyncResult asyncResult)
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper+<>c__DisplayClass4c<TSource, TInterface>.<ExecuteAsync>b__4a(IAsyncResult r)
System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<IAsyncResult, TResult> endFunction, Action<IAsyncResult> endAction, Task<TResult> promise, bool requiresSynchronization)
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.ExecuteAsync<TSource, TInterface>(DataServiceQuery<TSource> inner)
Microsoft.Azure.ActiveDirectory.GraphClient.AppRoleAssignmentCollection.<ExecuteAsync>b__2()
Merck.SeaMonkey.Api.AzureADApi.Controllers.UserController.GetApplicationRoleAssignments(string userId) in UserController.cs

新的 Microsoft Graph 客户端在这里不是一个选项,尽管我想我们可以下拉到基本 REST 接口,这对我们依赖的所有重试逻辑、结果解析等进行了一些工作图形客户端要做的事情。

更新: 给出异常的来源,我们假设在 OData 响应中序列化实体时存在问题。但是,使用 AD Graph Explorer,我们会看到一个非常简单的空值数组响应以及指向实体元数据文档的链接。我们通过删除和添加新的应用角色分配使问题经常出现,但我们不能强制它 100% 可靠地发生。看起来某些状态已损坏,可能在某些内部缓存中?

【问题讨论】:

    标签: c# asp.net-core microsoft-graph-api azure-ad-graph-api microsoft-graph-sdks


    【解决方案1】:

    我经常使用该 api 调用 - 但我对旧图使用直接休息 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; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-25
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      相关资源
      最近更新 更多