我正在尝试使用官方 nuget 库来使用 GraphAPI (https://github.com/microsoftgraph/msgraph-sdk-dotnet https://github.com/microsoftgraph/msgraph-sdk-dotnet)。然而,身份验证过程并不简单,而且没有很好的记录。
我是机器对机器场景中的 CSP 合作伙伴,因此不存在带有重定向 url 的 UI 应用程序,用户需要手动输入其凭据以同意访问。但这似乎是我发现的示例中有详细记录或可用的独特场景...甚至官方 CSP 文档也不清楚(https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider).
我之前在生产(和 TIP 环境)中使用了许多其他 API 作为 CSP,例如 MSOL、CrestAPI 和 AzureGraph,因此应用程序的所有配置和注册都不是问题。
是否可以在机器对机器场景中使用 MSAL 作为 CSP?有适用于我的用例的任何文档或示例吗?
UPDATE
我想我正走在好的道路上。
首先,我必须在 apps.dev.microsoft.com 上注册我的应用程序。我的应用程序之前已在 Portal.azure.com 上注册。看起来 AzureAD 和 Graph 对于应用程序必须注册的位置有不同的要求。
其次,我在这里使用示例:https://github.com/Azure-Samples/active-directory-dotnet-daemon-v2 https://github.com/Azure-Samples/active-directory-dotnet-daemon-v2 .
第三,当我提供我的 CSP TenantId 时,我可以调用 Graph API。但是,当我尝试使用我管理的租户之一的 TenantId 调用 Graph API 时,我得到了:
{ "error": {
"code": "Authorization_IdentityNotFound",
"message": "The identity of the calling application could not be established.",
"innerError": {
"request-id": "7cab3137-b3e7-4622-9123-e47f2c018c56",
"date": "2017-09-04T14:48:34"
} } }
(我的用例中无法拥有同意页面,因此我尝试使用以下方式为所有消费者预先同意我的应用程序:https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider)