title: Azure AD graph api working on local but fails when deployed
body: <p>I tried graphapi code from <a href="https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/tree/master/GraphConsoleAppV3" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/tree/master/GraphConsoleAppV3</a>. It worked on my local system. On local machine it pops up a window and ask for login. But When I deployed the application to azure web portal, it failed at the point where it gets the token sing Itenent. </p>
  
  <p><strong>"Error HRESULT E_FAIL has been returned from a call to a COM component"
  [COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.]</strong></p>
  
  <p>I think this is searching token from local system. Is my token retrieving option related to windows or web? Any suggestion on code changes.</p>
  
  <p>How can I replace this application to work when deployed. I think if we can change the ITenantDetail tenantDetail = GetTenantDetailsSync(client, UserModeConstants.TenantId);  code to one which gets info from user, this should work on web also.</p>
  
  <pre><code>private static ActiveDirectoryClient client;
  client = AuthenticationHelper.GetActiveDirectoryClientAsUser();
  ITenantDetail tenantDetail = GetTenantDetailsSync(client, UserModeConstants.TenantId);
  
  
  
   public static ITenantDetail GetTenantDetailsSync(IActiveDirectoryClient client, string tenantId)
      {
          ITenantDetail tenant = null;
          try
          {
              IPagedCollection&lt;ITenantDetail&gt; tenantsCollection = client.TenantDetails
                  .Where(tenantDetail =&gt; tenantDetail.ObjectId.Equals(tenantId)).ExecuteAsync().Result;
  
              List&lt;ITenantDetail&gt; tenantsList = tenantsCollection.CurrentPage.ToList();
  
              if (tenantsList.Count &gt; 0)
              {
                  tenant = tenantsList.First();
              }
          }
          catch (Exception ex)
          {
          }
  
          if (tenant == null)
          {
              return null;
          }
          else
          {
              TenantDetail tenantDetail = (TenantDetail)tenant;
              return tenantDetail;
          }
      }
  
  
  
  public static ActiveDirectoryClient GetActiveDirectoryClientAsUser()
          {
              Uri servicePointUri = new Uri(GlobalConstants.ResourceUrl);
              Uri serviceRoot = new Uri(servicePointUri, UserModeConstants.TenantId);
              ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
                  async () =&gt; await AcquireTokenAsyncForUser());
              return activeDirectoryClient;
          }
  
  public static async Task&lt;string&gt; AcquireTokenAsyncForUser()
          {
              return await GetTokenForUser();
          }
  
  public static async Task&lt;string&gt; GetTokenForUser()
          {
              if (TokenForUser == null)
              {
                  var redirectUri = new Uri("https://localhost");
                  AuthenticationContext authenticationContext = new AuthenticationContext(UserModeConstants.AuthString, false);
                  AuthenticationResult userAuthnResult = await authenticationContext.AcquireTokenAsync(GlobalConstants.ResourceUrl,
                      UserModeConstants.ClientId, redirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
                  TokenForUser = userAuthnResult.AccessToken;
              }
              return TokenForUser;
          }
  </code></pre>