简体   繁体   English

Office 365 API Microsoft Graph身份验证失败

[英]Office 365 APIs Microsoft Graph authentication failed

I registered sample app from Microsoft graph sample app 我从Microsoft graph示例应用程序注册了示例应用程序

And standard login is working but when I try to make it simplier by using this code: 标准登录正在工作,但是当我尝试使用以下代码使其更简单时:

        var authContext = new AuthenticationContext(Settings.AzureADAuthority);

        var token = authContext.AcquireToken(Settings.O365UnifiedAPIResource, new ClientCredential(Settings.ClientId, Settings.ClientSecret)).AccessToken;

I get the following error: Application with identifier '[ClientId here]' was not found in the directory microsoft.com 我收到以下错误: Application with identifier '[ClientId here]' was not found in the directory microsoft.com

Setting.O365UnifiedAPIResource = @"https://graph.microsoft.com/";
Settings.AzureADAuthority = @"https://login.microsoftonline.com/common";

Does anyone know what can be the problem? 有谁知道可能是什么问题?

Settings.AzureADAuthority = @"https://login.microsoftonline.com/{tenant_id or tenant_name}";

When acquiring the token by using the client credential (client id + client secret). 通过使用客户端证书(客户端ID +客户端密钥)获取令牌时。 You should specify the tenant explicitly. 您应该明确指定承租人。

For example: 例如:

https://login.microsoftonline.com/ {tenant_id} https://login.microsoftonline.com/ {tenant_id}

or 要么

https://login.microsoftonline.com/ {your_domain.onmicrosoft.com} https://login.microsoftonline.com/ {your_domain.onmicrosoft.com}

BTW, as this registration will be for the sample app, it will only have the Mail.Send permission which is delegated permission. 顺便说一句,因为此注册将针对示例应用程序,所以它将仅具有Mail.Send权限(即委派权限)。 To acquire the app token, you also need to grant the app level permission in Azure AD since your are acquiring the app token rather than the user token. 若要获取应用程序令牌,还需要在Azure AD中授予应用程序级别权限,因为您是在获取应用程序令牌而不是用户令牌。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Office 365图获得Microsoft Teams消息 - Office 365 Graph getting Microsoft Teams Messages 使用 Microsoft Graph 从 Office 365 邮箱中提取退回的电子邮件 - Fetch Bounced emails from Office 365 mailbox using Microsoft Graph 使用 Microsoft Graph 从 Office365 email 获取附件 - Get attachments from Office365 email using Microsoft Graph 在iOS中开发Microsoft Office 365 - Microsoft Office 365 Developing in iOS 当新电子邮件到达Office365电子邮件时,Microsoft Graph API中是否有任何事件 - Is there any Event in Microsoft Graph API when new email arrived in Office365 email c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片 - c# how to get office 365 user photo using microsoft graph api Microsoft 图表如何检索 Office 365 电子邮件的所有 SingleValueLegacyExtendedProperties - Microsoft graph how to retrieve ALL SingleValueLegacyExtendedProperties of an Office 365 e-mail Message Microsoft 图表如何将 Office 365 投票按钮添加到电子邮件 - Microsoft graph how to add Office 365 Voting Buttons to an e-mail Message 如何通过无缝身份验证从 microsoft word 2013 插件在 office 365 sharepoint 2013 站点中保存文档? - How to save document in office 365 sharepoint 2013 site from microsoft word 2013 addin with seamless authentication? Blazor(服务器端),具有组织/Office 365/Microsoft 帐户身份验证; 如何做本地多个角色? - Blazor (Server-Side) with Organizational/Office 365/Microsoft Account Authentication; How to do Local Multiple Roles?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM