title: What token to be used to generate UserAssertion in AAD in C#
body: <p>We want to use AcquireTokenAsync to acquire the tokens on behalf of user using the following syntax</p>
  
  <pre><code>public static async Task&lt;UserTokenCache&gt; GetAccessTokens(string userUniqueId)
      {
          UserTokenCache cache = null;
          AuthenticationContext authContext = null;
          ClientCredential credential = new ClientCredential(clientId, appKey);
          AuthenticationResult powerBIResult = null;
          AuthenticationResult graphResult = null;
          bool isAdalException = false;
          try
          {
              authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userUniqueId));
  
              powerBIResult = await authContext.AcquireTokenSilentAsync(pbiResourceID, credential, new UserIdentifier(userUniqueId, UserIdentifierType.UniqueId));
  
              graphResult = await authContext.AcquireTokenSilentAsync(graphResourceId, credential, new UserIdentifier(userUniqueId, UserIdentifierType.UniqueId));
  
              cache = new UserTokenCache
              {
                  GraphAccessToken = graphResult.AccessToken,
                  PBIAccessToken = powerBIResult.AccessToken,
                  PBITokenExpires = powerBIResult.ExpiresOn,
                  GraphTokenExpires = graphResult.ExpiresOn
              };
  
          }
          catch (JsonException je)
          {
              ExceptionLogger.LogInApplicationInsight(je);
              HttpContext.Current.GetOwinContext().Authentication.Challenge(
                         new AuthenticationProperties(),
                         OpenIdConnectAuthenticationDefaults.AuthenticationType);
          }
          catch (AdalException ae)
          {
              ExceptionLogger.LogInApplicationInsight(ae);
              if (ae.ErrorCode == "failed_to_acquire_token_silently")
              {
                  isAdalException = true;       
              }
              else
              {
                  HttpContext.Current.GetOwinContext().Authentication.Challenge(
                             new AuthenticationProperties(),
                             OpenIdConnectAuthenticationDefaults.AuthenticationType);
              }
          }
          catch (Exception ex)
          {
              ExceptionLogger.LogInApplicationInsight(ex);
          }
          if(isAdalException)
          {
              try
              {
  
                  string cacheValue = Convert.ToString(cacheManager.get(userUniqueId));
                  string decryptedCache = CryptographyUtility.Decrypt(cacheValue);
                  cache = JsonConvert.DeserializeObject&lt;UserTokenCache&gt;(decryptedCache);
  
                  UserAssertion pbiAssertion = new UserAssertion(cache.PBIAccessToken, "urn:ietf:params:oauth:grant-type:jwt-bearer", UserProperties.UserName);
                  UserAssertion graphAssertion = new UserAssertion(cache.GraphAccessToken, "urn:ietf:params:oauth:grant-type:jwt-bearer", UserProperties.UserName);
  
                  cache = null;
  
                  powerBIResult = await authContext.AcquireTokenAsync(pbiResourceID, credential, pbiAssertion);
                  graphResult = await authContext.AcquireTokenAsync(graphResourceId, credential, graphAssertion);
  
                  cache = new UserTokenCache
                  {
                      GraphAccessToken = graphResult.AccessToken,
                      PBIAccessToken = powerBIResult.AccessToken,
                      PBITokenExpires = powerBIResult.ExpiresOn,
                      GraphTokenExpires = graphResult.ExpiresOn
                  };
              } catch (Exception ex)
              {
                  ExceptionLogger.LogInApplicationInsight(ex);
              }
          }
          return cache;
  
      }
  </code></pre>
  
  <p>If we use cache.PBIAccessToken and cache.GraphAccessToken to calculate user assertions which are used in AcquireTokenAsync method, it is throwing the error that TenantId is mismatch. In this case, what is the token which needs to be used to calculate UserAssertion.</p>