none
Trying to log in to Azure Active Directory stalls for ~ 1 minute but only in Excel! RRS feed

  • Question

  • I'm using the following code, which I've started on its own thread

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {

                var Network = new oAuth2();

                System.Threading.Thread Login = new System.Threading.Thread(Network.TempMethod);

                Login.Start();

            }

    async public void TempMethod()

            {

                IntPtr hwnd = new IntPtr(); 

                authContext = new AuthenticationContext(authority);

                PlatformParameters p = new PlatformParameters(PromptBehavior.Auto, hwnd);

                AuthenticationResult result = null;

                result = await authContext.AcquireTokenAsync(todoListResourceId, clientId, redirectURI, p);

             }

    When the window pops up, the login box is unresponsive for more than a minute

    The same code launched from a Windows form works fine

    That's why I tried it on its own thread, using implementation above, but same result of long delay

    Can anyone pls help? This has only started happening v recently

    Monday, October 30, 2017 4:52 PM

All replies

  • Hi Journeyman42,

    is it full code that you posted above?

    if not, try to provide the full code and also try to provide which values you passed in arguments.

    you did not mentioned that which Excel version you are using currently.

    try to inform us your version.

    also try to check for any pending updates.

    if updates are available then try to update your Excel with latest updates may solve your issue.

    other then that try to use any other event like button click event on the ribbon or any other that get execute after the addin get load completely.

    it is possible that Addin is loading or any other process is running at that time which holds the login for some time.

    so try to check it and let us know about the result you get.

    we will try to provide you further suggestions to solve the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 31, 2017 2:57 AM
    Moderator
  • Thanks for the offer of help. Here is the full code, i've only obfuscated personal details

    namespace ExcelAddIn1
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {

                var Network = new oAuth2();

                System.Threading.Thread Login = new System.Threading.Thread(Network.TempMethod);

                Login.Start();




            }


    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.IdentityModel.Clients.ActiveDirectory;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Globalization;
    using System.Windows.Forms;
    using Newtonsoft.Json.Linq;
    using System.Configuration;
    using ExcelAddIn1.Properties;


    namespace ExcelAddIn1
    {
        public class oAuth2
        {

            private HttpClient httpClient = new HttpClient();
            private AuthenticationContext authContext = null;
            private Uri redirectURI = new Uri("https://mywebsite.azurewebsites.net/.auth/login/aad/callback");


            const string tenant = "mywebsite.onmicrosoft.com";
            const string clientId = "XXXXXXXXX-970a-4de4-ac29-XXXXXXX";
            const string aadInstance = "https://login.microsoftonline.com/{0}";
            static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
            public string todoListResourceId = "https://mywebsite.azurewebsites.net/api/";


            async public void TempMethod()

            {

                IntPtr hwnd = new IntPtr(); // handler for the window object we're going to display the login prompt at

                System.Diagnostics.Debug.WriteLine("Initialised the window");

                authContext = new AuthenticationContext(authority);

                System.Diagnostics.Debug.WriteLine("Set auth context");

                PlatformParameters p = new PlatformParameters(PromptBehavior.Auto, hwnd);

                System.Diagnostics.Debug.WriteLine("Set platform parameters");

                AuthenticationResult result = null;

                System.Diagnostics.Debug.WriteLine("Now awaiting result");

                result = await authContext.AcquireTokenAsync(todoListResourceId, clientId, redirectURI, p);

                System.Diagnostics.Debug.WriteLine("Returned result");

                if (result.IdToken != null)

                {

                    Properties.Settings.Default.AuthToken = result.AccessToken;

                    Properties.Settings.Default.ValidKey = true;

                    Properties.Settings.Default.Save();


               
                }

                else

                {


                    Properties.Settings.Default.ValidKey = false;

                
                }

            }

     
        }

    Tuesday, October 31, 2017 11:18 AM
  • Also, currently running Excel 2013, which doesn't work, but I also want it to work with 2010

    Tuesday, October 31, 2017 11:20 AM
  • Hi Journeyman,

    I found a similar thread below, is it yours?

    #Identity server login is unresponsive - windows update problem?

    https://social.msdn.microsoft.com/Forums/office/en-US/d5f50623-e702-47a0-bb5d-9880f04bb795/identity-server-login-is-unresponsive-windows-update-problem?forum=exceldev

    I would suggest you keep following above thread, and share us more information.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 7, 2017 9:57 AM