title: OIDC correlation failed in MS Teams Blazor App but works in Browser
body: <p>Im coding a Blazor App (ASP.NET Core 3.1) for MS Teams. <br/>
  In the App user have to authentificate themself via an authentification popup. <br/>
  The app is hostet via internal IIS on localhost and is tunneled via ngrok in MS Teams.<br/>
  In Blazor there are Blazor Components which are saved via <code>@attribute [Authorize]</code> flag which is discribed in <a href="https://docs.microsoft.com/de-de/aspnet/core/blazor/security/?view=aspnetcore-3.1" rel="nofollow noreferrer">Blazor Security</a>.<br />
  The App is registeres at Azure AD Portal correctly.<br/>
  When i try to authentificate via Azure AD in the App which is hosted in MS Teams the App reads the user credentials and send them to Azure.
  I think at the redirect the Error <code>An unhandled exception occurred while processing the request. Exception: Correlation failed. Unknown location Exception: An error was encountered while handling the remote login. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler&lt;TOptions&gt;.HandleRequestAsync()</code> is thrown.<br/>
  The call is looking like this: <br/></p>
  <pre><code>https://login.microsoftonline.com/[tenantid]/oauth2/authorize?client_id=[clientId]&amp;redirect_uri=https%3A%2F%2Flocalhost%3A44302%2Fsignin-oidc&amp;response_type=id_token&amp;scope=openid%20profile&amp;response_mode=form_post&amp;nonce=[nonce]&amp;state=[state]&amp;x-client-SKU=ID_NETSTANDARD2_0&amp;x-client-ver=5.5.0.0
  </code></pre>
  <br/>
  Also  there is no cookie created.<br/>
  The interesting thing is in the Browser (Chrome) the authentificaion flow works fine and also the cookie is created correctly. Also the Blazor AuthentificationStateProvider gets the UserState correctly from the popup.<br/>
  My Login Page with the Authentification Popup: <br/>
  <pre><code>function login() {
          $(&quot;.auth-data&quot;).hide();
          microsoftTeams.authentication.authenticate({
              url: window.location.origin + &quot;/AzureAD/Account/SignIn&quot;,
              width: 600,
              height: 535,
              successCallback: function (result) {
                  window.location.replace(window.location.origin + &quot;/&quot;);
              },
              failureCallback: function (reason) {
                  console.log(&quot;Login failed: &quot; + reason);
                  if (reason === &quot;CancelledByUser&quot; || reason === &quot;FailedToOpenWindow&quot;) {
                      console.log(&quot;Login was blocked by popup blocker or canceled by user.&quot;);
                  }
                  // At this point we have to get the user involved, so show the login button
                  $(&quot;#btnLogin&quot;).show();
                  $(&quot;.auth-data&quot;).hide();
                  $(&quot;#divError&quot;).text(reason).show();
              }
          });
      }
  </code></pre>
  <p>My Startup Page: <br/></p>
  <pre><code>private void CheckSameSite(HttpContext httpContext, CookieOptions options)
      {
          if (options.SameSite == SameSiteMode.None)
          {
              var userAgent = httpContext.Request.Headers[&quot;User-Agent&quot;].ToString();
              // TODO: Use your User Agent library of choice here.
              if (userAgent.Contains(&quot;Chrome&quot;))
              {
                  options.SameSite = SameSiteMode.Unspecified;
              }
          }
      }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
              options.OnAppendCookie = cookieContext =&gt;
                  CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
              options.OnDeleteCookie = cookieContext =&gt;
                  CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
              options.HttpOnly = HttpOnlyPolicy.None;
              options.Secure = CookieSecurePolicy.Always;
          });
  
          services
              .AddAuthentication(AzureADDefaults.AuthenticationScheme)
              .AddAzureAD(options =&gt; Configuration.Bind(&quot;AzureAd&quot;, options));
  
          services.Configure&lt;JwtBearerOptions&gt;(
          AzureADDefaults.JwtBearerAuthenticationScheme, options =&gt;
          {
              options.TokenValidationParameters.NameClaimType = &quot;name&quot;;
          });
  
          services.AddRazorPages();
          services.AddServerSideBlazor();
          services.AddBlazoredLocalStorage();
      }
  
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          app.UseCookiePolicy();
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler(&quot;/Error&quot;);
              app.UseHsts();
          }
  
          app.UseHttpsRedirection();
          app.UseStaticFiles();
  
          app.UseRouting();
  
          app.UseAuthentication();
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllers();
              endpoints.MapBlazorHub();
              endpoints.MapFallbackToPage(&quot;/_Host&quot;);
          });
      }
  </code></pre>
  <p>As you can see i used the method which is mentioned on another stack overflow question <a href="https://stackoverflow.com/questions/59849097/oidc-correlation-failed-in-microsoft-teams-authentication-popup-no-problems-in">Stack Overflow</a>
  this dont work for my task.<br/>
  I could need help if there is something wrong configured in my Startup or somewhere else beacause authentification via Teams dont work for me just via the Browser.</p>