我正在尝试使用REST API调用Microsoft Graph,但遇到了一些问题。我的应用程序最终将是部署到Azure的Web应用程序,我需要在没有登录用户的情况下通过REST调用Graph。
在尝试调试时,我尝试制作了最简单的应用程序。该应用程序正试图使用Graph从Azure Active Directory中读取用户的配置文件。
我在AAD中注册了我的应用,因此我有一个租户,客户ID和客户密码。至此,我已经在AAD和Graph API下授予了所有许可(出于测试目的)。我可以从AAD获得令牌,但是当我使用该令牌调用Graph API时,我会获得401 - Unauthorizedwith Access Token Validation Error。
我已经搜索了此错误,却没有发现任何适用的方法。
编辑:添加权限后,我还向我的应用程序授予了权限。
我已经从各种样本中抓取了一些片段,以尝试使其正常工作。这是代码:
var tenant = "tenant ID";
var clientID = "app ID";
// I've tried graph.microsoft.com and graph.microsoft.com/.default
var resource = "https://graph.microsoft.com/user.read.all";
var secret = "client secret";
string token;
using(var webClient = new WebClient())
{
var requestParameters = new NameValueCollection();
requestParameters.Add("scope", resource);
requestParameters.Add("client_id", clientID);
requestParameters.Add("grant_type", "client_credentials");
requestParameters.Add("client_secret", secret);
var url = $"https://login.microsoftonline.com/{tenant}/oauth2/token";
var responseBytes = await webClient.UploadValuesTaskAsync(url, "POST", requestParameters);
var responseBody …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何使用Microsoft Graph JavaScript Client创建日历事件。
我已经设法检索了必要的内容,accessToken并且可以与API进行交互(即检索事件,日历,前10名电子邮件),但是我不确定如何使用API创建事件。
client
.api('/me/events')
.header('X-AnchorMailbox', emailAddress)
Run Code Online (Sandbox Code Playgroud)
我是否使用post发送事件json对象?
以下是我在Azure AD中邀请用户使用的代码。
我收到“未经授权”的回复。我不确定缺少哪些权限/设置。有谁有主意。
string accessToken = await AuthenticationHelper.GetTokenForApplication ();
InvitationModel invite = new InvitationModel ();
invite.invitedUserEmailAddress = user.Email;
invite.inviteRedirectUrl = ConfigurationManager.AppSettings["InviteRedirectUrl"];
invite.sendInvitationMessage = true;
using (HttpClient client = new HttpClient ()) {
client.BaseAddress = new Uri ("https://graph.microsoft.com");
client.DefaultRequestHeaders.Accept.Add (
new MediaTypeWithQualityHeaderValue ("application/json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue ("Bearer", accessToken);
HttpResponseMessage response =
client.PostAsJsonAsync<InvitationModel> ("v1.6/invitations", invite).Result;
dynamic inviteResult =
response.Content.ReadAsAsync<dynamic> ().Result;
if (inviteResult.status != "Error") { }
}
Run Code Online (Sandbox Code Playgroud) 我正在使用面向 Microsoft Graph 的 REST API 并PATCH请求设置accountEnabled为false. 这工作正常,帐户被暂停,我无法登录。
但是,当我GET离开时,/v1.0/users/{{id}我没有accountEnabled恢复状态。因此,如果不将用户帐户的状态保存在某个本地数据库中(我不想这样做),我无法知道用户帐户是否被禁用。
如何检索用户的 accountEnabled 状态?
我有一个使用 Angular 构建的 Outlook Office 插件,它使用了该Office.js库。加载项的目的是对当前显示的消息执行一次性操作。一旦为加载项中的操作单击提交按钮,就无需再打开加载项。
有没有办法从应用程序内部完全关闭加载项框架?例如,类似的东西Office.close();。
我正在将v1 Azure AD身份验证URL(/common/oauth2/authorize)用于需要的多租户应用程序admin_consent.
我试图添加一个新范围Directory.AccessAsUser.All.当我的所有其他作用域都是"应用程序"级别权限时,这是我要求的第一个"委托"权限.
当我添加新的委派范围并提示管理员重新同意时,其他范围从返回的AccessToken和响应scope参数中消失.只Directory.AccessAsUser.All存在于该access_token scp领域.
这种行为会发生什么原因吗?我很肯定我们正在推广admin_consent并且管理员是同意的.
我正在使用在apps.dev.microsoft.com中创建的几个应用程序。我正在使用的身份验证 URL 是
https: //login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id={client_id}
&redirect_uri={redirect_uri}
&response_type=code id_token
&state=state
&nonce=c7a966a3-d63d-4348-8ab8-bd445b0e9bb1
&response_mode=form_post
&scope=openid email profile https://graph.microsoft.com/user.readBasic.all
Run Code Online (Sandbox Code Playgroud)
在我的用例中,我正在从声明中捕获tid, oid, iss, sub... 声明id_token。
对于我的一个应用程序,某些用户oid的id_token. 但我可以获取其他应用程序,并且我认为创建应用程序没有任何区别。
哪些原因可能导致oid索赔丢失?
我正在使用的范围:openid email user.read
我目前正在使用v4.6.2开发一个C#项目,Visual Studio刚刚建议对下面的代码进行代码更改.
我的问题是,我从未见过is用于以这种方式创建新变量实例的关键字.
原始代码是:
var authInfo = inputs.FirstOrDefault(i =>
typeof(SoapAuthenticationBase).IsAssignableFrom(i.GetType()));
if (authInfo is SoapAuthenticationBase)
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2017建议:
if (inputs.FirstOrDefault(i =>
typeof(SoapAuthBase).IsAssignableFrom(i.GetType()))
is SoapAuthBase authenticationContract)
Run Code Online (Sandbox Code Playgroud)
我在'is'关键字上检查了Microsoft的文档,但没有发现任何解释这种语法的内容.
以这种方式添加了什么版本的C#?
我们有一个应用程序,我们将用户登录名以domain\username. 我们通过 Windows 进行身份验证,然后通过将domain\username我们从用户获得的信息与我们的数据库进行匹配来从我们的数据库中获取其他信息。
现在,他们想要迁移到云端。我们通过 Azure AD 中的应用对用户进行身份验证。但是,user我们返回的标识符是first.last@domain.com。
我已经摆弄了https://graph.microsoft.com/v1.0/users/email和 select 命令来尝试获取“旧”名称。但是,我还没有找到如何获得它。
他们迁移到云端的原因是他们正在合并两个 AD。所以一些用户将是 DomainA 和一些 DomainB,但在同一个租户中。所以我的第一个想法是尝试将邮件转换为其他格式。但是,两种不同的 AD 具有不同的命名标准。一个有DOMAINA\fila(名字的两个第一个字母和姓氏的两个第一个字母),另一个有DOMAINB\firlas. 尝试以这种方式解决它也感觉很丑陋。
是否可以domain\username通过 Microsoft Graph获取格式化的用户登录名?
我正在遵循没有用户指南的获取访问权限来编写将调用 Microsoft Graph 的 Python 脚本。
此脚本将从 cron 调度,因此它无法获得管理员同意(因此使用客户端凭据进行授权)。我能够使用此调用成功获取令牌:
request_url = "https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token"
data = {
'Host' : 'login.microsoftonline.com',
'Content-Type' : 'application/x-www-form-urlencoded',
'client_id' : 'my-client-id-1234',
'scope' : 'https://graph.microsoft.com/.default',
'client_secret' : client_secret,
'grant_type' : 'client_credentials'
}
response = requests.post(url = request_url, data = data)
Run Code Online (Sandbox Code Playgroud)
然后,我尝试使用有效令牌通过此调用获取用户列表:
request_url = "https://graph.microsoft.com/v1.0/users"
headers = {
'Authorization' : 'Bearer ' + token,
'Host' : 'graph.microsoft.com'
}
response = requests.get(url = request_url, headers = headers)
Run Code Online (Sandbox Code Playgroud)
问题是我收到一个Authorization_IdentityNotFound错误:
<Response [401]>
{
"error": {
"code": …Run Code Online (Sandbox Code Playgroud)