【问题标题】:AADSTS70001: Application is not supported for this API versionAADSTS70001:此 API 版本不支持应用程序
【发布时间】: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


    【解决方案1】:

    您正在尝试将 MSAL 与 v1 端点一起使用。从使用ConfidentialClientApplication 可以看出这一点。您需要改用 ADAL(Azure AD 身份验证库)。 或者在https://apps.dev.microsoft.com注册v2的应用程序。

    您可以从 NuGet 获取 ADAL:https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/

    您可以在此处找到使用 ADAL 的示例应用程序:https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect

    您的 OnAuthorizationCodeReceived 需要如下所示:

        private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification context)
        {
            var code = context.Code;
    
            ClientCredential credential = new ClientCredential(clientId, appKey);
            string userObjectID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
            AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
    
            // If you create the redirectUri this way, it will contain a trailing slash.  
            // Make sure you've registered the same exact Uri in the Azure Portal (including the slash).
            Uri uri = new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path));
    
            AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(code, uri, credential, graphResourceId);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-10
      • 2016-02-25
      • 2018-01-17
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      相关资源
      最近更新 更多