AADSTS70001:应用程序' 574c1791-d632-4180-91e4-38094a8a3a77'此API版本不支持此功能

时间:2015-12-23 08:48:48

标签: asp.net outlook oauth-2.0 office365 office365api

我试图在我的单页.net应用程序中使用office365 api而不是mvc。我在网站上获得了mvc .net项目C#的源代码。

$('#project_items').mixItUp();

我将代码转换为vb.net,我收到了错误的请求错误,指出我的应用程序在执行时不支持此api版本。代码在WebForm1.aspx中,重定向uri链接在webform2.aspx

 public async Task<ActionResult> SignIn()
            {
                string authority = "https://login.microsoftonline.com/common";
                string clientId = System.Configuration.ConfigurationManager.AppSettings["ida:ClientID"]; 
                AuthenticationContext authContext = new AuthenticationContext(authority);

                // The url in our app that Azure should redirect to after successful signin
                Uri redirectUri = new Uri(Url.Action("Authorize", "Home", null, Request.Url.Scheme));

                // Generate the parameterized URL for Azure signin
                Uri authUri = await authContext.GetAuthorizationRequestUrlAsync(scopes, null, clientId, redirectUri, UserIdentifier.AnyUser, null);

                // Redirect the browser to the Azure signin page

                return Redirect(authUri.ToString());
            }



         // Note the function signature is changed!
                public async Task<ActionResult> Authorize()
                {
                    // Get the 'code' parameter from the Azure redirect
                    string authCode = Request.Params["code"];

                    string authority = "https://login.microsoftonline.com/common";
                    string clientId = System.Configuration.ConfigurationManager.AppSettings["ida:ClientID"]; ;
                    string clientSecret = System.Configuration.ConfigurationManager.AppSettings["ida:ClientSecret"]; ;
                    AuthenticationContext authContext = new AuthenticationContext(authority);

                    // The same url we specified in the auth code request
                    Uri redirectUri = new Uri(Url.Action("Authorize", "Home", null, Request.Url.Scheme));

                    // Use client ID and secret to establish app identity
                    ClientCredential credential = new ClientCredential(clientId, clientSecret);

                    try
                    {
                        // Get the token
                        var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(
                            authCode, redirectUri, credential, scopes);

                        // Save the token in the session
                        Session["access_token"] = authResult.Token;

                        // Try to get user info
                        Session["user_email"] = GetUserEmail(authContext, clientId);

                        return Redirect(Url.Action("Inbox", "Home", null, Request.Url.Scheme));
                    }
                    catch (AdalException ex)
                    {
                        return Content(string.Format("ERROR retrieving token: {0}", ex.Message));
                    }
                }

我是如何注册应用程序的。事实上,当我为mvc应用程序使用相同的客户端ID和客户端密钥时,它执行时没有任何错误,但是当我在我的单个Web应用程序中使用它时,它会抛出此错误。 请帮忙。我做错了什么

0 个答案:

没有答案