【发布时间】:2017-06-13 09:45:16
【问题描述】:
我有一个 ASP.NET MVC Web 应用程序,它需要检查用户是否是 Azure Active Directory 中特定组的成员。为了实现这一点,我将使用 Microsoft Graph API,因此我从here 下载了他们的示例并进行了试用,并且运行良好。
我的下一步是让它使用我自己的 AppId、AppSecret 和 RedirectUri 运行,这就是我遇到麻烦的地方。在 Azure 中,我去了 AAD 的“应用程序注册”,并确保添加了应用程序。我打开了应用程序并复制了 AppId 的“应用程序 ID”,创建了一个密钥并将其用作 AppSecret。我检查了所有权限并按下“授予权限”并将我的 URL 添加到回复 URL。我还将权限属性从https://login.microsoftonline.com/common/v2.0 更改为https://login.windows.net/xxxxxx.onmicrosoft.com。
当我运行应用程序并按“登录”时,我会正确进入登录屏幕,但是当我尝试登录时它会崩溃。在下面的代码中运行 AcquireTokenByAuthorizationCodeAsync 时会发生崩溃:
AuthorizationCodeReceived = async (context) =>
{
var code = context.Code;
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
ConfidentialClientApplication cca = new ConfidentialClientApplication(
appId,
redirectUri,
new ClientCredential(appSecret),
new SessionTokenCache(signedInUserID, context.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase));
string[] scopes = graphScopes.Split(new char[] { ' ' });
AuthenticationResult result = await cca.AcquireTokenByAuthorizationCodeAsync(scopes, code);
},
AuthenticationFailed = (context) =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
我在 AuthenticationFailed 中收到的错误消息如下所示:
AADSTS70001:此 API 版本不支持应用程序“xxxxxxxx-4f81-4508-8dcb-df5b94f2290f”。跟踪 ID:xxxxxxxx-d04c-4793-ad14-868810f00c00 相关 ID:xxxxxxxx-ab83-4805-baea-8f590991ec0c 时间戳:2017-06-13 10:43:08Z
有人可以向我解释错误消息的含义吗?我应该尝试不同的版本吗?我已经尝试过 Microsoft.Graph v1.3.0 / Microsoft.Graph.Core v1.4.0 和 Microsoft.Graph v1.4.0 / Microsoft.Graph.Core v1.5.0。
【问题讨论】:
标签: azure azure-web-app-service azure-active-directory microsoft-graph-api