title: Asp.Net Mvc Web App PowerBI Login HRESULT E_FAIL Error
body: <p>I am trying to have a single sign-in web app through azure that has an initial Microsoft login and then no second login. At the moment I am just trying to get 2 logins to work but when running locally I can get the app to work and show the Power BI reports using a dual login. But whenever I publish the app up to the Azure host and I try to access the power BI page instead of having a Microsoft popup to log in it just suffers from this error.</p>
  
  <pre><code>    [COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.]
     Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask(Task`1 task) +89
     MultiTenantWebApp.Controllers.PowerBiController.Autenticate() in C:\Users\G4Fro\Source\Repos\Intern\MultiTenantWebApp\MultiTenantWebApp\Controllers\PowerBiController.cs:165
     MultiTenantWebApp.Controllers.PowerBiController.MakeGroupDictionary() in C:\Users\G4Fro\Source\Repos\Intern\MultiTenantWebApp\MultiTenantWebApp\Controllers\PowerBiController.cs:64
     MultiTenantWebApp.Controllers.PowerBiController.EmbedReport() in C:\Users\G4Fro\Source\Repos\Intern\MultiTenantWebApp\MultiTenantWebApp\Controllers\PowerBiController.cs:32
     lambda_method(Closure , ControllerBase , Object[] ) +62
     System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
     System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +169
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
     System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;BeginInvokeSynchronousActionMethod&gt;b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
     System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
     System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3d() +50
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass46.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +228
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass33.&lt;BeginInvokeActionMethodWithFilters&gt;b__32(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +26
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +100
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
     System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
     System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
     System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +577
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +157
  </code></pre>
  
  <p>Any help would be greatly appreciated as I have no idea why it works offline but not online and I don't know how to understand the stack trace</p>
  
  <p>This is the Authentication code</p>
  
  <pre><code>private void Authenticate()
          {
              string clientID = ""; // We have our client ID here that was created in power BI dev apps
              string redirectUri = "https://localhost:44367/";
              string resourceUri = "https://analysis.windows.net/powerbi/api";
              string authorityUri = "https://login.windows.net/common/oauth2/authorize";
  
              if (token == null)
              {
                  AuthenticationContext authContext = new AuthenticationContext(authorityUri);
                  token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;
              }
              else
              {
                  return;
              }
          }
  </code></pre>