我们在 .NET Core 2.1上运行,在运行以下查询时有时会出现异常“此平台不支持安全二进制序列化”:
await _adClient.Users[userId].AppRoleAssignments.ExecuteAsync();
Run Code Online (Sandbox Code Playgroud)
重新执行查询通常有效,因此满足某些条件,即在后续请求中未尝试(或成功?)二进制序列化?也就是说,如果我重新启动服务,它通常也会对第一个请求起作用。
我们正在使用旧的 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
Run Code Online (Sandbox Code Playgroud)
新的 Microsoft Graph 客户端不是这里的一个选项,尽管我想我们可以下拉到基本 REST 接口,这对我们依赖于图客户端的所有重试逻辑、结果解析等有点工作去做。
更新:给出异常的来源,我们假设在序列化 OData 响应中的实体时存在问题。但是,使用 AD Graph Explorer,我们会看到一个非常简单的响应,即空值数组以及指向实体元数据文档的链接。我们通过删除和添加新的应用程序角色分配使问题经常再次发生,但我们不能强制它 100% 可靠地发生。看起来某些状态正在损坏,也许在某些内部缓存中?
c# azure-ad-graph-api asp.net-core microsoft-graph-sdks microsoft-graph-api
我正在使用 Graph 在现有团队中创建一个新的私人频道。在此之后,我想在该频道中创建一个新选项卡。在对 tabs 端点执行 POST 时,我几乎总是收到带有消息的 404 NotFound,No active channel found with channel id: 19:690...但在创建私有频道后等待几分钟后,tabs 端点可用,我可以创建选项卡。
如果创建标准频道,这总是成功的。
我可以使用 Graph SDK 和 Graph Explorer 重现这一点。
我可以尝试在使用 Graph SDK 以下列方式创建频道后列出可用选项卡,以便能够查看问题:
var graphClient = new GraphServiceClient(authProvider);
var channelRequest = new Channel()
{
DisplayName = "Test",
MembershipType = ChannelMembershipType.Private,
Members = new ChannelMembersCollectionPage()
{
new AadUserConversationMember
{
Roles = new List<String>()
{
"owner"
},
AdditionalData = new Dictionary<string, object>()
{
{"user@odata.bind", "https://graph.microsoft.com/v1.0/users('{user-id}')"}
}
}
}
};
var channel = await graphClient.Teams[teamId].Channels …Run Code Online (Sandbox Code Playgroud) microsoft-teams microsoft-graph-sdks microsoft-graph-teams microsoft-graph-api
Microsoft webhook 订阅正在发送奇怪的正文数据,并且validationToken参数中没有文本。Microsoft Graph 团队中有人可以提供帮助吗?
这就是我要发送的内容(出于隐私原因,我更改了实际域名notificationUrl)。
{
"changeType": "created",
"notificationUrl": "https://myapp.com/version-test/api/1.1/wf/msgraphvalidation",
"resource": "me/mailFolders/inbox/messages",
"expirationDateTime": "2018-08-27T18:23:45.9356913Z"
}
Run Code Online (Sandbox Code Playgroud)
这是使用上述信息将 POST 发送到“ https://graph.microsoft.com/v1.0/subscriptions ”或“ https://graph.microsoft.com/beta/subscriptions ”后在正文中返回的内容。
Request data
{
"bold": "\u001b[1m\u001b[22m",
"underline": "\u001b[4m\u001b[24m",
"strikethrough": "\u001b[9m\u001b[29m",
"italic": "\u001b[3m\u001b[23m",
"inverse": "\u001b[7m\u001b[27m",
"grey": "\u001b[90m\u001b[39m",
"black": "\u001b[30m\u001b[39m",
"yellow": "\u001b[33m\u001b[39m",
"red": "\u001b[31m\u001b[39m",
"green": "\u001b[32m\u001b[39m",
"blue": "\u001b[34m\u001b[39m",
"white": "\u001b[37m\u001b[39m",
"cyan": "\u001b[36m\u001b[39m",
"magenta": "\u001b[35m\u001b[39m",
"greyBG": "\u001b[49;5;8m\u001b[49m",
"blackBG": "\u001b[40m\u001b[49m",
"yellowBG": "\u001b[43m\u001b[49m",
"redBG": "\u001b[41m\u001b[49m",
"greenBG": "\u001b[42m\u001b[49m",
"blueBG": "\u001b[44m\u001b[49m",
"whiteBG": "\u001b[47m\u001b[49m",
"cyanBG": "\u001b[46m\u001b[49m",
"magentaBG": "\u001b[45m\u001b[49m",
"rainbow": "",
"zebra": "", …Run Code Online (Sandbox Code Playgroud) 我想使用 GraphClient 向用户添加扩展。我在任何地方都找不到合适的 C# 代码。任何人都可以帮忙吗?
Dictionary<string, object> addData = new Dictionary<string, object> {
{
"HoloFlag",
currentUser.UserPrincipalName
}
};
var extPatchObject = new OpenTypeExtension();
extPatchObject.ExtensionName = "com.holobeam3.extension";
extPatchObject.AdditionalData = addData;
try {
var extension = await _graphClient
.Me
.Extensions
.Request()
.AddAsync(extPatchObject);
Debug.Log(extension);
} catch (Exception ex) {
Debug.Log(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试的。这将返回“访问被拒绝”异常,但在访问用户的现有扩展或其他Me端点时没有问题。
在我的 C# 应用程序中,我将 Microsoft Graph SDK 与 Azure AD 实现结合使用。
请建议我如何根据搜索参数在我的组织中搜索用户(全球联系人)。例如,如果“Raj”是搜索参数,我应该能够获取名称包含“Raj”或电子邮件地址包含“Raj”的所有用户。我发现这个方法可以获取所有用户 - “graphClient.Users.Request().GetAsync();”。但是,由于这种方法的响应有限,我没有得到我想要搜索的内容。
谢谢,沙希达
我正在尝试执行读取用户配置文件的简单操作。在我授予此操作的相关权限后,我可以通过编写以下代码来获取令牌:
static void Main(string[] args)
{
var getToken = new GetTokenEntity()
{
Authority = "https://login.microsoftonline.com/common",
Resource = "https://graph.microsoft.com",
UserName = "myusername",
ClientId = "appclientidguid",
Password = "somepass"
};
var graphClient = new GraphServiceClient("https://graph.microsoft.com", new DelegateAuthenticationProvider(async(requestMessage) =>
{
var authResult = await GetToken(getToken);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", authResult.AccessToken);
}));
var inbox = GetMessages(graphClient).GetAwaiter().GetResult();
}
public async static Task<AuthenticationResult> GetToken(GetTokenEntity getToken)
{
var authenticationContext = new AuthenticationContext(getToken.Authority);
var authenticationResult = await authenticationContext
.AcquireTokenAsync(getToken.Resource, getToken.ClientId,
new UserPasswordCredential(getToken.UserName, getToken.Password));
return authenticationResult;
}
public async …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 graph /getSchedule api 来检查会议冲突。但是,我不太了解请求输入字段“availabilityViewInterval”的功能和用法。
我的基本要求是传递开始和结束日期时间并查看资源是否可用(空闲/忙碌)。虽然我可以在 /getSchedule Api 中获取该信息,但不确定请求和响应中的某些字段。
“availabilityViewInterval”:这是一个请求字段,在文档中声明为可选,但在使用图形客户端时,我需要为此传递值。它接受 5 到 1440 之间的 int 值,但不确定它的作用以及我应该传递的值是什么?
“availabilityView”:这是一个响应字段,返回一个字符串值。但我无法理解它。这个值有什么用以及它是如何计算的?它的意义是什么以及如何利用它?
要求:
ICalendarGetScheduleCollectionPage response = graphClient.users("usrEmailAddress").calendars(calendar.id)
.getSchedule(schedulesList,endTime,startTime,availabilityViewInterval)
.buildRequest()
.post();
Run Code Online (Sandbox Code Playgroud)
下面是我的示例响应(两次请求中的availabilityViewInterval值都是5,但响应availabilityView是不同的):
**"availabilityView": "22"**,
"scheduleItems": [
{
"isPrivate": false,
"status": "busy",
"subject": "Test Meeting again",
"location": "",
"start": {
"dateTime": "2020-06-12T10:58:45.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2020-06-12T11:08:45.0000000",
"timeZone": "UTC"
}
}
],
"workingHours": {
"daysOfWeek": [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday"
],
"startTime": "08:00:00.0000000",
"endTime": "17:00:00.0000000",
"timeZone": {
"name": "India Standard Time"
} …Run Code Online (Sandbox Code Playgroud) java microsoft-graph-sdks microsoft-graph-calendar microsoft-graph-teams microsoft-graph-api
我目前正在我的 .NET Core 3.1 应用程序中测试 MS Graph .NET Core SDK 客户端。目的是提供我自己的本地 Web API 用户服务,该服务从 Azure B2C AD 执行更新/更改/获取用户。
在我的预期解决方案中,我将拥有各种 HTTP 客户端微服务,它们将向我的用户服务 SDK 客户端调用 API 命令,而不是直接使用 REST 调用 Azure Graph API。
在我的用户服务应用程序中,我尝试通过对发送到 Azure 的实际 SDK 命令使用存储库/接口方法来保持简洁。然后,这个相同的用户服务应用程序使用我自己的 WEB API 将数据返回到我的本地 HTTP 客户端。想象一下这个用户服务应用程序作为中间人的效果。
下图总结了环境:
这样做的目的是减少对图形服务使用的功能进行更改或添加时的工作,即在我自己的本地应用程序中提供一些通信标准化,并促进更好的关注点分离。此外,如果 MS 对 Graph API 进行更改,那么我只会更新用户服务应用程序,而不是在所有 HTTP 客户端应用程序中进行代码更改。希望这是有道理的。
无论如何,现在进入正题!我的问题的原因:
(请耐心等待,我是 REST 和使用接口的新手)
Graph SDK 客户端和 Azure 中的 Graph Service API 之间遇到的任何错误都将记录在我的用户服务应用程序中,即我将在第一时间捕获的大量 json 错误详细信息,但是我根本不需要通过此级别的详细信息返回到我所有本地调用 HTTP 客户端。
我想要实现的是一种识别/捕获 SDK 客户端和图形服务之间遇到的任何 HTTP 状态代码错误的方法,以及错误的一些基本详细信息,即简短描述,并且仅传递这些较低级别的错误将详细信息返回给我的本地 HTTP 客户端,即保持干净。
我正在努力了解如何在我的代码中执行此操作,特别是考虑到我同时使用接口使其变得更加复杂。MS 文档确实提供了有关使用图形服务的预期错误代码列表的信息,但没有示例解释如何处理此信息以便将相关(但较轻版本的信息)传递回另一个来源。
示例场景:
我们使用Microsoft Graph API Beta 版本通过以下代码从 Azure AD 检索所有用户。API 在响应中仅返回 100 个用户,并且为了使用分页响应,我们尝试了NextPageRequest属性。但它总是会回报null财产NextPageRequest。因此,它永远不会进入 while 循环来检索其余用户。
测试版 SDK 版本:4.0.1.0
代码:
List<User> usersList = new List<User>();
IGraphServiceUsersCollectionPage users = await graphClient.Users.Request().GetAsync();
// Add the first page of results to the user list
usersList.AddRange(users.CurrentPage);
// Fetch each page and add those results to the list
while (users.NextPageRequest != null)
{
users = await users.NextPageRequest.GetAsync();
usersList.AddRange(users.CurrentPage);
}
log.Info("Users count: " + usersList.Count.ToString());
return usersList;
Run Code Online (Sandbox Code Playgroud)
我关注的参考链接:
我有以下代码,它根据过滤器返回所有用户。问题是它只返回 100 个用户,但我知道还有更多。
private List<User> GetUsersFromGraph()
{
if (_graphAPIConnectionDetails == null) ReadParametersFromXML();
if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();
var users = graphServiceClient
.Users
.Request()
.Filter(_graphAPIConnectionDetails.UserFilter)
.Select(_graphAPIConnectionDetails.UserAttributes)
.GetAsync()
.Result
.ToList<User>();
return users;
}
Run Code Online (Sandbox Code Playgroud)
该方法仅返回 100 个用户对象。我的 Azure 门户管理员报告说应该接近 60,000。