我想集成office365服务管理API以从中收集事件。我想使用客户端凭据方式来使用服务来进行服务调用,但我收到了以下错误,
{
"错误":" invalid_client",
" error_description":" AADSTS50048:主题必须与客户断言中的发行人索赔匹配。
\ r \ nTrace ID:1ad7acd8-3945-4fe0-a313-07638eb76e42 \ r \ n相关ID:a6c3a3c9-b737-4bfc-894f-3086c3ce8dfa \ r \ n时间戳:2016-06-09 07:20:15Z&#34 ;,
" error_codes":[50048 ],
" timestamp":" 2016-06-09 07:20:15Z",
" trace_id的":" 1ad7acd8-3945-4fe0-a313-07638eb76e42",
" CORRELATION_ID":" a6c3a3c9-b737-4bfc-894f-3086c3ce8dfa"
}
我使用以下doc进行集成, 为了获得客户端的声明, https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx我得到了这个。但对于Access令牌, https://msdn.microsoft.com/en-us/library/office/dn707383.aspx我没有将此作为对错误的回应。 请有人帮帮我:)
答案 0 :(得分:0)
你是如何获得client_assertion的?您提供的link没有描述如何获取'client_assertion'。它使用应用程序的ID和密码获取令牌,该令牌不支持Office 365 Management API。您可以参考blog来了解'client_assertion'。
这是一个C#代码示例,它使用ADAL获取客户端凭据流的访问令牌:
string clientId = "{clientId}";
string certThumbprint = "{copy from mmc}";
certThumbprint = certThumbprint.Replace("\u200e", string.Empty).Replace("\u200f", string.Empty).Replace(" ", string.Empty);
string apiResourceId = "https://manage.office.com";
X509Certificate2 cert = null;
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
string authority = "https://login.windows.net/{yourTentant}";
var authContext = new AuthenticationContext(authority);
try
{
store.Open(OpenFlags.ReadOnly);
cert = store.Certificates.Find(X509FindType.FindByThumbprint, certThumbprint, false)[0];
}
finally
{
store.Close();
}
var certCred = new ClientAssertionCertificate(clientId, cert);
AuthenticationResult result = null;
try
{
result = await authContext.AcquireTokenAsync(apiResourceId, certCred);
}
catch (Exception ex)
{
}