o365 calendar API not returning calendar

时间:2015-10-29 15:47:58

标签: calendar outlook office365 office365-apps office365api

I am following instructions provided at https://dev.outlook.com/RestGettingStarted/Tutorial/dotnet to get my web application integrated with user's outlook calendar. I am being redirected to login into my microsoft account and it returns to my return url with the code parameter populated. However when I try to generate token out of that code it returns empty without any error.

Can someone please advise?

Following code is to generate token from the code:

            // 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 Content("Access Token: " + authResult.Token);
                }
                catch (AdalException ex)
                {
                    return Content(string.Format("ERROR retrieving token: {0}", ex.Message));
                }
            }

0 个答案:

没有答案