我成功地为 Microsoft Graph 设置了 OAuth 2.0 客户端凭据,我获得了身份验证令牌没问题,订阅了多个用户的电子邮件 webhook,并收到了这些电子邮件通知。
在 Azure 门户中,我将应用程序设置为具有“以任何用户身份发送邮件”的 Microsoft Graph 应用级别权限。
我正在尝试使用 Graph 转发电子邮件,但出现BadRequest错误:
{
"error": {
"code": "BadRequest",
"message":
"Current authenticated context is not valid for this request. This occurs when a request is made to an endpoint that requires user sign-in. For example, /me requires a signed-in user. Acquire a token on behalf of a user to make requests to these endpoints. Use the OAuth 2.0 authorization code flow for mobile and native …Run Code Online (Sandbox Code Playgroud) 需要 SignalR,在 5 月 30 日之前开始我的项目,当时 ASP .NET Core 2.1 稳定版本发布,我选择使用 ASP .NET Core 2.1 RC1。
然而,一旦稳定版本发布,我自然希望放弃预览版本并升级到稳定版本。这个怎么做?
为了实现这一目标,我访问https://www.microsoft.com/net/download/visual-studio-sdks并从那里下载了 .NET Core 2.1 x64 安装程序。但是,安装后,我现在无法编译我的项目。编译失败并出现以下错误:
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
1>------ Build started: Project: mon, Configuration: Debug Any CPU ------
1>C:\Users\m\source\repos\mon\mon\mon.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Workspaces 2.8.0-beta3 requires Microsoft.CodeAnalysis.CSharp (= 2.8.0-beta3) but version Microsoft.CodeAnalysis.CSharp 2.8.0 was resolved.
1>C:\Users\m\source\repos\mon\mon\mon.csproj : error NU1107: Version conflict detected for …Run Code Online (Sandbox Code Playgroud) 我有一个API,该API需要来自Microsft Graph API的一些数据。我当时正在考虑在我的API中实现一个端点,以刷新令牌并使用该令牌从前端进行调用。我不知道这是最佳还是安全,因此我提出了问题。
编辑1:为了更好地了解我所拥有的,这就是我目前的逻辑。请告诉我这是否正确。
用户请求我的API的授权终结点,该终结点具有Azure的秘密密钥,然后将用户重定向到Microsft oAuth登录页面。登录oAuth后,Microsoft会将用户重定向到我的API,在该API中将JWT令牌保存在用户的Cookie中,以便用户可以随时刷新令牌。
为了刷新令牌,用户只需简单地调用myapi.com/auth/microsoft/token,就拥有密钥,然后刷新。
我在 Azure AD 中创建了一个多租户应用程序当我尝试获取访问令牌并签入 jwt.io 时,我发现 scp(范围)丢失。
//string authority = "https://login.microsoftonline.com/{0}/common/oauth2/v2.0/token?&response_type=code&scope=openid%20profile%20User.ReadWrite%20User.ReadBasic.All%20Sites.ReadWrite.All%20Contacts.ReadWrite%20People.Read%20Notes.ReadWrite.All%20Tasks.ReadWrite%20Mail.ReadWrite%20Files.ReadWrite.All%20Calendars.ReadWrite";
//string authority = "https://login.microsoftonline.com/{0}/common/oauth2/v2.0/token?&scope=https://graph.windows.net/directory.read%20https://graph.windows.net/directory.write";
//string authority = "https://login.microsoftonline.com/{0}/common/oauth2/v2.0/token";
//string authority = "https://login.microsoftonline.com/{0}";
//string authority = "https://login.microsoftonline.com/{0}/common/oauth2/v2.0/token?&response_type=code&scope=openid%20profile%20User.Read%20User.ReadWrite%20User.ReadBasic.All";
//string authority = "https://login.microsoftonline.com/{0}/oauth2/token?scope=User.ReadBasic.All";
//string authority = "https://login.microsoftonline.com/{0}/oauth2/token?scope=User.ReadBasic.All";
string authority = "https://login.microsoftonline.com/common/oauth2/v2.0/token?response_type=token&scope=User.ReadBasic.All";
Run Code Online (Sandbox Code Playgroud)
我尝试了很多权威 URL 的组合
string graphResourceId = "https://graph.microsoft.com";
string clientId = "XXXX";
string secret = "XXXX";
authority = String.Format(authority, tenantId);
AuthenticationContext authContext = new AuthenticationContext(authority);
var accessToken = authContext.AcquireTokenAsync(graphResourceId, new ClientCredential(clientId, secret)).Result;
Run Code Online (Sandbox Code Playgroud)
如何获取 microsoft.graph 资源的范围?
我有一个 ReactJs 前端向 API 发出请求。两者都托管在 Azure 中,并在 AAD 中注册应用程序。
我曾经能够使用 v1.0 身份验证端点,并为 API 创建有效令牌:
https://login.microsoftonline.com/common/oauth2/authorize?client_id=<AAD_WEB_APP_ID>&resource=<AAD_API_ID>&response_type=token ...
Run Code Online (Sandbox Code Playgroud)
如果我正确理解文档,则 v2.0 中不允许/不可能使用这种类型的身份验证流程:
但是,该 Web API 只能从具有相同应用程序 ID 的应用程序接收令牌。您无法从具有不同应用程序 ID 的客户端访问 Web API。客户端将无法请求或获取对您的 Web API 的权限。
从 v1.0 更改为 v2.0 的原因是我需要访问 Microsoft Graph(特别是组)。
我的问题是:如何创建access_token适用于 Microsoft Graph 和我的 API 的应用程序?如果这是不可能的,正确的身份验证流程是什么?
我想将我的应用程序与 Microsoft Graph 连接。我在 Azure 中创建了我的网络应用程序(我有我的client_id和client_secret)。我可以发送请求以获取授权码https://login.microsoftonline.com/common/oauth2/v2.0/authorize。
问题是,当我使用 Postman(带选项)发送请求POST以获取访问令牌https://login.microsoftonline.com/common/oauth2/v2.0/token(正如 “使用权限”部分中所述form-data)时,我收到“AADSTS9000410:格式错误的 JSON”错误:
{
"error": "invalid_request",
"error_description": "AADSTS9000410: Malformed JSON.\r\nTrace ID: f5c1dd4b-ad43-4265-91cb-1b7392360301\r\nCorrelation ID: 1dea54ed-bb43-4951-bc9e-001877fe427b\r\nTimestamp: 2019-01-14 21:38:42Z",
"error_codes": [9000410],
"timestamp": "2019-01-14 21:38:42Z",
"trace_id": "f5c1dd4b-ad43-4265-91cb-1b7392360401",
"correlation_id": "1dea54ed-bb43-4951-bc9e-001878fe427b"
}
Run Code Online (Sandbox Code Playgroud)
此外,当我在 Postman 中使用原始选项发送相同的请求时,我收到“AADSTS900144:请求正文必须包含以下参数:'grant_type'”:
{
"error": "invalid_request",
"error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID:a7c2f8f4-1510-42e6-b15e-b0df0865ff00\r\nCorrelation ID:e863cfa9-0bce-473c-bdf6-e48cfe2356e4\r\nTimestamp: 2019-01-1421:51:29Z",
"error_codes": [900144],
"timestamp": "2019-01-14 21:51:29Z",
"trace_id": "a7c2f8f4-1510-42e6-b15e-b0df0865ff10",
"correlation_id": "e863cfa9-0bce-473c-bdf6-e48cfe2356e3"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我application/json在 Postman …
我目前正在尝试在 Node.js 中使用 Microsoft Graph 直接登录日历/用户。
到目前为止我所做的如下:
登录帐户并确保它当前有日历(电子邮件在 下注册@outlook.com)。
转到azure门户并创建一个新的AAD名称“Calendar Api”带有返回URL的Web APIhttp://localhost:3000
AAD -> 应用程序注册 -> 名称:测试,回复 url:localhost:3000,Microsoft Graph 所需的权限(用户读/写、日历读/写)、Windows AAD (offline_access)、授予权限、生成新密钥没有有效期。
转到 Postman 并开始根据以下 URL 生成新令牌:
https://login.microsoftonline.com/{APP_ID_URI}.onmicrosoft.com/oauth2/v2.0/token
Run Code Online (Sandbox Code Playgroud)
client_credentialshttps://graph.microsoft.com/.default我有200 OK一个令牌。
"aud": "https://graph.microsoft.com",
"roles": [
"User.ReadWrite.All",
"Calendars.Read",
"Calendars.ReadWrite"
],
Run Code Online (Sandbox Code Playgroud)
GET ON -> https://graph.microsoft.com/v1.0/users/with Authorization Bearer,上面的令牌将返回代码状态 200 以及我在步骤 1 中使用的用户帐户。
GET ON ->https://graph.microsoft.com/v1.0/calendars/使用 Authorization Bearer 并返回上述令牌"Resource not found for the segment 'calendars'."
上车 -> …
我正在尝试通过 Microsoft Graph Api (SDK) 获取驱动器的项目并尝试了以下选项:
_graphServiceClient.Drives[driveInfo.Id].Items.Request().GetAsync():,不幸的是,这会导致错误消息错误消息“请求格式错误或不正确”和代码“invalidRequest”。_graphServiceClient.Drives[driveInfo.Id].Request().GetAsync()但是,如果我执行,我会取回所有驱动器,但Items属性为null.
_graphServiceClient.Drives[driveInfo.Id].Request().Expand(d => d.Items).GetAsync(),这也会导致错误消息“请求格式错误或不正确”和代码“invalidRequest”。
我不知道如何从这里继续,仍在研究中,但目前文档让我一无所知。任何人都成功.Expand()或从云端硬盘获取实际文件?
谢谢,是
我正在尝试使用 Microsoft Graph (C# SDK) 在 SharePoint 中的现有文件夹下创建一个文件夹。我知道使用 Graph API 时在 SharePoint 或 OneDrive 上创建文件夹应该是相同的,但我仍然找不到任何好的在线参考。我找到的唯一一篇文章是一篇旧文章,其中只有一个 JavaScript 示例。
我有一个根文件夹A,我想B在A.
这是代码:
var driveRequestBuilder = graphClient
.Sites[SharePointSiteId]
.Lists[ListId]
.Drive;
var folderRequestBuilder = driveRequestBuilder
.Root
.ItemWithPath("A");
var folderDriveItem = folderRequestBuilder
.Request()
.GetAsync()
.Result; // This returns the root folder "A"'s info
var subFolderDriveItem = new DriveItem()
{
Name = "B",
Folder = folderDriveItem.Folder
};
var result = folderRequestBuilder
.Request()
.CreateAsync(subFolderDriveItem)
.Result;
Run Code Online (Sandbox Code Playgroud)
最后一行代码抛出一个异常AggregateException(因为 TPL),其中包含内部异常:
var …Run Code Online (Sandbox Code Playgroud) 我有一个删除多个事件的方法。目前代码如下:
public async Task DeleteEvents(IEnumerable<string> eventExternalIds)
{
foreach(var eventExternalId in eventExternalIds)
{
await DeleteEvent(eventExternalId);
}
}
public async Task DeleteEvent(string eventExternalId)
{
await GraphClient
.Users[Username]
.Calendars[CalendarName]
.Events[eventExternalId]
.Request()
.DeleteAsync();
}
Run Code Online (Sandbox Code Playgroud)
我想它不会在删除大量 id 时表现良好。有没有办法批量删除它们而不是单独删除它们?