标签: microsoft-graph-api

如何模拟 Microsoft Graph API SDK 客户端?

我在我的项目中使用了 Microsoft Graph SDK 来调用图形 API,为此我需要使用 GraphServiceClient。要使用 GraphServiceClient,我必须添加一些辅助类,其中 SDKHelper 是具有 GetAuthenticatedClient() 方法的静态类。由于被测方法与静态的 SDKHelper 紧密耦合,因此我创建了一个服务类并注入了依赖项。

下面是控制器和方法,

public class MyController
{
    private IMyServices _iMyServices { get; set; }

    public UserController(IMyServices iMyServices)
    {
        _iMyServices = iMyServices;
    }
    public async Task<HttpResponseMessage> GetGroupMembers([FromUri]string groupID)
    {
        GraphServiceClient graphClient = _iMyServices.GetAuthenticatedClient();
        IGroupMembersCollectionWithReferencesPage groupMembers = await _iMyServices.GetGroupMembersCollectionWithReferencePage(graphClient, groupID);
        return this.Request.CreateResponse(HttpStatusCode.OK, groupMembers, "application/json");
    }
}
Run Code Online (Sandbox Code Playgroud)

服务类,

public class MyServices : IMyServices
{
    public GraphServiceClient GetAuthenticatedClient()
    {
        GraphServiceClient graphClient = new GraphServiceClient(
            new DelegateAuthenticationProvider(
                async (requestMessage) =>
                {
                    string accessToken …
Run Code Online (Sandbox Code Playgroud)

c# moq asp.net-web-api microsoft-graph-api

7
推荐指数
1
解决办法
5743
查看次数

用于 onPremisesExtensionAttributes 的 Microsoft Graph 过滤器

我有一个具有以下属性的 Microsoft Graph 用户:

"onPremisesExtensionAttributes": {
            "extensionAttribute1": "attr1",
            "extensionAttribute2": null,
            "extensionAttribute3": null,
            "extensionAttribute4": null,
             etc.
        },
Run Code Online (Sandbox Code Playgroud)

我似乎找不到关于如何过滤此属性的任何文档或示例。我试过了:

https://graph.microsoft.com/beta/users?$filter=extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/any(x:startswith(x,'attr1'))
Run Code Online (Sandbox Code Playgroud)

所有这些都会导致错误的请求,所以很明显有问题。

"code": "BadRequest",
"message": "Invalid filter clause",
Run Code Online (Sandbox Code Playgroud)

问题:如何针对 onPremisesExtensionAttributes 或任何其他包含命名属性列表的属性(例如 extensionAttribute1...n)设置过滤器的格式?对于字符串列表(例如 proxyAddresses),您可以执行以下操作:

$filter=proxyAddresses/any(x:startswith(x,%27smtp:myemail%27))
Run Code Online (Sandbox Code Playgroud)

office365 azure-active-directory microsoft-graph-api

7
推荐指数
1
解决办法
1211
查看次数

如何使用 Microsoft Graph Beta API 下载 Teams 聊天消息附件?

A@microsoft.graph.downloadUrl不适用于使用 Microsoft Graph Beta API 的聊天消息附件。

我最近在msgraph-sdk-javascript存储库中发布了一个有关通过 beta graph api 下载 Microsoft Teams 聊天消息附件的问题。

https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/200

问题是目前无法获取@microsoft.graph.downloadUrl这些聊天附件。我在那里发布了一个解决方法,如下所示,但这需要额外的 api 调用,并且可能很脆弱,因为它涉及解析聊天附件的contentUrl.

function getDownloadUrl(attachment: ChatMessageAttachment, team?: Team): string {
  const url = new URL(attachment.contentUrl as string);
  const path = url.pathname.split('/').slice(4).join('/');
  if (team) {
    return `/groups/${team.id}/drive/root:/${path}`;
  } else {
    return `/me/drive/root:/${path}`;
  }
}
Run Code Online (Sandbox Code Playgroud)

维护者要求我microsoft-graph-javascript在这里发布我的问题。

microsoft-graph-api

7
推荐指数
0
解决办法
1035
查看次数

如何使用 MSAL 获取访问令牌以代表控制台应用程序中的用户调用 MS Graph?

我有一个 SPA 应用程序,它使用 AAD v2 身份验证与我的后端 Web API 进行通信。现在,我正在开发一个控制台应用程序来代表登录到 SPA 应用程序的用户调用 Microsoft Graph。

我有用户的有效访问令牌(用于调用后端 Web API)。我想使用此访问令牌来请求用于访问 MS Graph 的新令牌。

以下是使用 MSAL.NET 请求具有 MS Graph 范围的新访问令牌的控制台应用程序的代码:

string clientId = "<clientId>";
string clientSecret = "<clientSecret>";
string accessToken = "<validAccessTokenForWebApi>";
string assertionType = "urn:ietf:params:oauth:grant-type:jwt-bearer";
string[] scopes = new string[] { "User.Read", "Mail.Send" };
string graphAccessToken = null;

try
{
    var app = ConfidentialClientApplicationBuilder
                .Create(clientId).WithClientSecret(clientSecret).Build();

    var userAssertion = new UserAssertion(accessToken, assertionType);

    var result = app.AcquireTokenOnBehalfOf(scopes, userAssertion)
                    .ExecuteAsync().GetAwaiter().GetResult();

    graphAccessToken = result.AccessToken;
}
catch (MsalServiceException ex) …
Run Code Online (Sandbox Code Playgroud)

c# azure-active-directory azure-ad-msal microsoft-graph-api

7
推荐指数
1
解决办法
2万
查看次数

Python Django /w Microsoft Graphs - 我不断收到值错误“auth_code_flow 中缺少状态”

Python Django /w Microsoft Graphs -

我正在按照此 Microsoft 教程使用 Microsoft Graph 构建 Django 应用程序(在我现有的 Django Web 应用程序上使用它),但我遇到了身份验证问题:https: //learn.microsoft.com/en-us/graph/tutorials /Python

我正在执行“添加 Azure AD 身份验证”步骤,在实施后,我点击登录按钮并输入凭据...并且我不断收到值错误“auth_code_flow 中缺少状态”。

“回调”方法只是使其达到 result=get_token_from_code(request) 然后失败。

这是 get_token_from_code 方法:

def get_token_from_code(request):
  cache = load_cache(request)
  auth_app = get_msal_app(cache)

  # Get the flow saved in session
  flow = request.session.pop('auth_flow', {})

  result = auth_app.acquire_token_by_auth_code_flow(flow, request.GET)
  save_cache(request, cache)

  return result
Run Code Online (Sandbox Code Playgroud)

我想做的是最终从我的网络应用程序在线访问 Excel。

任何帮助是极大的赞赏!

python django microsoft-graph-api

7
推荐指数
2
解决办法
3338
查看次数

如何使用固定输入创建 GraphServiceClient 的 IAuthenticationProvider 对象

我正在尝试从我的 Java 应用程序连接到 Microsoft Share Point。Microsoft Graph SDK for Java 的文档不是很清楚。

我正在尝试启动 Graph 客户端,同时通过自定义 GUI 或配置文件提供所需的凭据。

我正在尝试按照以下方式进行但可以

IGraphServiceClient client = GraphServiceClient.builder().authenticationProvider(authenticationProvider).buildClient();

Run Code Online (Sandbox Code Playgroud)

我需要“authenticationProvider”对象是一个实现 IAuthenticationProvider 的类,但是它不清楚要添加什么参数或如何创建这个对象。有没有人以前尝试过这个,构建客户端并提供所需凭据的正确方法是什么?

java sharepoint microsoft-graph-sdks microsoft-graph-api

6
推荐指数
2
解决办法
5949
查看次数

当 includeResourceData=true 时,用于 MS 图形创建订阅的 webhooks 失败

 {
       "changeType": "created,updated,deleted",
       "notificationUrl": "https://somewebsite.com/mswebhook/graph/notifications",
       "resource": "/teams/{team-id}/channels/{channel-id}/messages",
       "expirationDateTime": "2019-12-30T09:41:21Z",
       "clientState": "",
       "includeResourceData": true,
       "encryptionCertificate": "TUlJQklUQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FRNEFNSUlCQ1FLQ0FRQlhFL0xOZjVYYVY4ZFlXbWFuSU9qUwphSnhyUG1tN0dHN0lWOGYwV2RjZDltbUkvaTVXQzhCNFBYaVBKREtKTnVFL2QvMXo5TndSbjR1UFBQQm9sN1BWCmdudVJ6UmZJSVEvUW1TZjYwUi9LUnYybHVlZzVwNW84Qk5UNDczdTRCbVZJVHNBWlF1eG43RGdnUi9JZlQzSVgKelpMdzNXWitDYzJyS1crblpmbUwwU0NiN21EL3RTZ3VqQUJPVEVvS0xBODkvNWhUamhuNzcvWHJzUTYrV1hMVgpKL3NtVDJvU3R3TzBnYXRIRUkwWkRSL0VYNkdVWDRRRVI4M0puS2hPSDJrZzZQNlZUMDFGUEw0Nk5WemZydWE4ClVob052Z0VlQStPY2xBOU5mUUpJQnVKUVFTbGZ0TmhYODJtVEdhVEtBTFN1bWZieUNac1ljQ3l4MXQ5RXF6Qi8KQWdNQkFBRT0=",
       "encryptionCertificateId": "id",
       "lifecycleNotificationUrl": "https://somewebsite.com/mswebhook/graph/notifications"
    }
Run Code Online (Sandbox Code Playgroud)

当这个请求是从邮递员发出时它正在给

{
  "error": {
    "code": "InvalidRequest",
    "message": "System.Security.Cryptography.CryptographicException: Cannot find the requested object.\r\n\r\n   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n   at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte[] rawData)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)\r\n   at Microsoft.Graph.Encryptor.Encryptor.ValidateCertificate(String certificate, String& errorMessage) in X:\\bt\\1070414\\repo\\src\\Dev\\Notifications\\Notifications.Azure\\Encryptor\\Encryptor.cs:line 293",
    "innerError": {
      "request-id": "e578bdba-2c47-41d7-a0da-5395b05e4203",
      "date": "2019-12-31T06:57:59"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

没有 includeResourceData 属性,订阅和通知工作正常。我在选择加密证书属性时遇到问题。目前我正在加密证书中传递 Base64 位编码的 2048 位 RSA 公钥(在线生成)。

webhooks postman microsoft-graph-api

6
推荐指数
0
解决办法
205
查看次数

在 Microsoft Graph API 中,获得管理员同意的应用程序是否可以为批准它的管理员之外的其他用户生成令牌?

我在 Microsoft Active Directory 中注册了一个多租户应用程序,该应用程序使用管理员同意来获取对 Microsoft Graph API 中某些应用程序范围 API 的访问权限。它使用/token端点获取令牌,然后调用这些图形 API。它工作得很好。 https://docs.microsoft.com/en-us/graph/auth-v2-service#token-request

现在我想增强我的应用程序以访问一些委托(用户)范围 API,这些 API 不允许在应用程序范围内进行访问。我的应用程序已配置为在管理员同意时向管理员请求这些委派权限。但我想以目录中的每个用户的身份调用这些 API ,而不是安装我的应用程序的管理员。

重要的是,让组织中的每个用户单独完成我的应用程序的 OAuth 流程对我来说是不可行的。

那可能吗?我可以通过用我的应用程序令牌交换用户令牌来以某种方式模拟用户吗?管理员是否可以以编程方式执行某些操作,以作为我的应用程序的个人用户生成令牌,就像他们已通过 OAuth 流程一样?

oauth-2.0 microsoft-graph-api

6
推荐指数
1
解决办法
144
查看次数

Microsoft graph : 使用 Put 请求 Java 更新文档

基于 MS 图形文档,我看到我可以更新一个 driveItem(文件)并将其放在特定的共享点驱动器中。该应用程序作为守护程序运行(无需用户登录)。

为此,我使用这个入口点:

PUT /drives/{drive-id}/items/{item-id}/content
Run Code Online (Sandbox Code Playgroud)

我尝试使用主类进行编码并传递现有参数。要更新文档,我调用方法更新文档:

UpdateDocumentResponseModel updatedDocument = fileGraphs.updateDocument(token, DRIVELIBID, DOCUMENTID, INPUTPATH, DOCUPDATE);
Run Code Online (Sandbox Code Playgroud)

被调用的方法旨在构建 URL 并为 PUT 请求准备数据:

public UpdateDocumentResponseModel updateDocument(String accessToken,
                                                  String driveLibId,
                                                  String documentId,
                                                  String inpuPath,
                                                  String docName) throws MalformedURLException {
    String fullPath = inpuPath + docName;
    URL url = new URL("https://graph.microsoft.com/v1.0/drives/" + driveLibId + "/items/" + documentId + "/content");
    return requestsBuilder.updateDocument(accessToken, url, fullPath);
}
Run Code Online (Sandbox Code Playgroud)

现在在这个阶段我必须提出请求:

public UpdateDocumentResponseModel updateDocument(String accessToken, URL url, String fullPath) {
    UpdateDocumentResponseModel returnValue = new UpdateDocumentResponseModel();

    try {
        CloseableHttpClient client = …
Run Code Online (Sandbox Code Playgroud)

java sharepoint-online microsoft-graph-api

6
推荐指数
1
解决办法
162
查看次数

通过调用 Microsoft Graph API(测试版)获取通话记录?

我是 Microsoft Graph API 的新手,我的最终目标是创建一个 Power BI 报告来显示 Microsoft Teams 调用相关矩阵。

文档中我可以看到 HTTP 示例(https://graph.microsoft.com/beta/communications/callRecords/ {id})。文档中有几件事不清楚。

  1. 我在哪里可以获得在示例请求中使用的呼叫ID
  2. 获取呼叫数据需要CallRecords.Read.All权限,我需要在哪里设置这个权限以及过程是什么。

microsoft-graph-api

6
推荐指数
1
解决办法
2239
查看次数