我有以下代码(从 Microsoft Learn 复制),在 Microsoft.Graph 4.54.0 上运行良好
var authProvider = new DelegateAuthenticationProvider(async (request) => {
// Use Microsoft.Identity.Client to retrieve token
var assertion = new UserAssertion(token.AccessToken);
var result = await clientApplication.AcquireTokenOnBehalfOf(scopes, assertion).ExecuteAsync();
request.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
});
Run Code Online (Sandbox Code Playgroud)
然后,我使用 Microsoft.Graph 5.0.0 和 Microsoft.Graph.Core 3.0.0 创建了一个新项目,这给出了无法找到 DelegateAuthenticationProvider 的错误。
如何创建可与 GraphServiceClient 一起使用的 AuthenticationProvider?
c# oauth-2.0 azure-ad-msal asp.net-core-webapi microsoft-graph-api
我正在尝试创建一个 C# 控制台应用程序来连接到图形 API 并从租户中获取来自 AzureAD 的用户列表。我已经注册了应用程序,管理员给了我以下内容
使用 sdk,我需要使用的 C# 代码如下所示(https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=cs):
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var users = await graphClient.Users
.Request()
.GetAsync();
Run Code Online (Sandbox Code Playgroud)
但是,控制台应用程序将作为批处理运行,因此根本没有用户交互。因此,为了提供 authProvider,我在 MS 文档站点上关注了这篇文章:https ://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS
而且我认为出于我的目的,我需要使用“客户端凭据 OAuth 流程”。该 URL 上显示的代码。但这里也是。
IConfidentialClientApplication clientApplication = ClientCredentialProvider.CreateClientApplication(clientId, clientCredential);
ClientCredentialProvider authProvider = new ClientCredentialProvider(clientApplication);
Run Code Online (Sandbox Code Playgroud)
问题是 Visual Studio 无法识别 ClientCredentialProvider 类。我不确定要导入哪个程序集。我在顶部使用以下用途。
using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Clients;
using Microsoft.IdentityModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Run Code Online (Sandbox Code Playgroud)
我对 GitHub 存储库不是很有经验,我使用的是 Visual …
我正在创建一个加载项,我将使用组织许可来销售该加载项。
我已经在加载项上实施了身份验证方案。我目前正在要求User.Read使用 Azure v2 端点进行可靠身份验证的范围。为了获取我正在查询的用户信息
https://graph.microsoft.com/v1.0/me
Run Code Online (Sandbox Code Playgroud)
为了正确测试用户的许可证,我需要提取用户的组织标识。但是,我从 Grah 请求中收到的用户信息极其精简。对于 AAD 帐户,架构类似于:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
businessPhones: [],
displayName: "FirstName LastName",
givenName: "FirstName",
id: "unique-id",
jobTitle: null,
mail: "First.LastName@COMPANYDOMAIN.COM",
mobilePhone: null,
officeLocation: null,
preferredLanguage: null,
surname: "LastName",
userPrincipalName: "FILastName@COMPANYDOMAIN.COM"
}
Run Code Online (Sandbox Code Playgroud)
如果我使用
https://graph.microsoft.com/BETA/me
Run Code Online (Sandbox Code Playgroud)
我获得了更多信息,但没有任何信息可以帮助我确定用户组织的唯一 ID。
是否需要使用不同的范围来获取用户组织的信息?如果没有,我可以依靠解析用户电子邮件中的域名作为用户组织的唯一 ID 吗?我需要查询不同的 API 吗?
如果有帮助,在用户使用 AD 进行身份验证后,我会收到以下响应:
{
access_token: "eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEWDhHQ2k2SnM2U0s4MlRzRDJQYjdyN1VLTzdJSDJSLWpTcmpScU9..."
expires_at: Fri May 18 2018 07: 18: 42 GMT - 0400(Eastern Daylight Time) {}
expires_in: "3599"
provider: "Microsoft"
scope: "https://graph.microsoft.com/User.Read"
session_state: "012f4565-31bb-..."
state: …Run Code Online (Sandbox Code Playgroud) 使用访问令牌初始化客户端时,Microsoft graph 抛出以下异常
访问令牌是在初始化客户端之前生成的,并且相同的令牌在 post-man 中也有效
我做错了什么?
代码
let graphClient = graph.Client.init({
// Use the provided access token to authenticate
// requests
authProvider: (done) => {
done(null, accessToken);
}
});
Run Code Online (Sandbox Code Playgroud)
邮递员回应
启用 MFA 后连接 Microsoft Azure AD 时,我遇到如下错误。在此之前它已连接。今天登录时,要求我在手机(Microsoft Authenticator APP)中启用此安全功能。除非添加此功能,否则我无法访问 Microsoft 365 中的 MS Outlook。
我正在使用WSO2 Outlook Connector与 Microsoft Graph API 建立连接
错误:
"error":"interaction_required","error_description":"AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '00000002-0000-0ff1-ce00-000000000000
Run Code Online (Sandbox Code Playgroud) wso2 azure-active-directory multi-factor-authentication microsoft-graph-api
我正在尝试使用microsoft graph onedrive api在 onedrive 上上传文件。我正在使用身份验证客户端凭据提供程序的方法
喜欢:
// /.default scope, and preconfigure your permissions on the
// app registration in Azure. An administrator must grant consent
// to those permissions beforehand.
var scopes = new[] { "https://graph.microsoft.com/.default" };
// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "my-tenantid";
// Values from app registration
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
// using …Run Code Online (Sandbox Code Playgroud) 我在尝试使用 Microsoft Graph 编写脚本以将 Excel 文件上传到 OneDrive 然后读取 Excel 文件时出错。
我按照Microsoft 文档在没有用户的情况下获取访问令牌。我成功获得了访问令牌,但在使用访问令牌调用 OneDrive API 时出错。
这是回应:
{
"error": {
"code": "BadRequest",
"message": "Tenant does not have a SPO license.",
"innerError": {
"request-id": "5ec31d17-3aea-469f-9078-de3608f11d0d",
"date": "2017-10-10T04:34:05"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在调用图形 API 时需要拥有 SPO 许可证以及如何获取它。由于此错误消息,所以我正在尝试购买 SPO 许可证。
根据此文档,我认为我应该在许可证页面中看到许多产品,但是在使用 Azure 门户登录并转到许可证页面时,我只看到 2 个产品:Azure AD Premium 和 Enterprise Mobility Suite:

我正在尝试对内部网的 Azure AD 和 Graph 进行身份验证(基于 Orchard CMS),这在我的本地机器上按预期运行,但是,当访问将是生产站点的站点时(已经在我们的内部 dns 上设置了 ssl ),我有时会收到上述错误,它相对不一致,我部门中的其他人在访问时通常会收到此错误。
我的身份验证控制器如下:
public void LogOn()
{
if (!Request.IsAuthenticated)
{
// Signal OWIN to send an authorization request to Azure.
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
public void LogOff()
{
if (Request.IsAuthenticated)
{
ClaimsPrincipal _currentUser = (System.Web.HttpContext.Current.User as ClaimsPrincipal);
// Get the user's token cache and clear it.
string userObjectId = _currentUser.Claims.First(x => x.Type.Equals(ClaimTypes.NameIdentifier)).Value;
SessionTokenCache tokenCache = new SessionTokenCache(userObjectId, HttpContext);
HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
}
SDKHelper.SignOutClient();
HttpContext.GetOwinContext().Authentication.SignOut( …Run Code Online (Sandbox Code Playgroud) 我正在使用 Microsoft Graph API,我正在创建一个文件夹,如下所示:
var driveItem = new DriveItem
{
Name = Customer_Name.Text + Customer_LName.Text,
Folder = new Folder
{
},
AdditionalData = new Dictionary<string, object>()
{
{"@microsoft.graph.conflictBehavior","rename"}
}
};
var newFolder = await App.GraphClient
.Me
.Drive
.Items["id-of-folder-I-am-putting-this-into"]
.Children
.Request()
.AddAsync(driveItem);
Run Code Online (Sandbox Code Playgroud)
我的问题是如何检查此文件夹是否存在以及它是否确实获得了文件夹的 ID?
我想在 MS Teams 中显示的日历上创建/阅读会议。我有 Office 365 商业必需品付费订阅,用于登录 MS Teams。想在下面澄清:
1) 我在 MS Teams 中看到的带有上述订阅计划的日历默认是 Office 365 订阅的前景?
2) 我想在 Teams 日历上自动安排/阅读会议。我没有在 MS Graph 中看到 Teams API。我可以使用哪些图形 API?或者此类调用是否会添加到 Teams Graph API 中?
3) MS Teams 可以与 google 或 Outlook 以外的任何日历集成吗?
提前致谢
c# ×5
onedrive ×2
asp.net-mvc ×1
multi-factor-authentication ×1
node.js ×1
oauth-2.0 ×1
office-js ×1
office365 ×1
orchardcms ×1
wso2 ×1