title: Microsoft.Identity Platform login loop
body: <p>I have been playing with Microsoft.Identity platform and trying to get it to work with the basic templates in aspnetcore 6.0, but I get stuck in an infinite login loop.</p>
  <p>I am using projects created from the templates for web app and web api (using these commands <code>&quot;dotnet new webapi --force --auth IndividualB2C&quot;</code> and <code>&quot;dotnet new webapp --force --auth IndividualB2C&quot;</code>) and then updated the appsettings in both to connect to my Azure B2C tenant.</p>
  <p><strong>WEB APP</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"AzureAdB2C": {
          "CallbackPath": "/signin-oidc",
          "ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "ClientSecret": "xxxxx",
          "Domain": "xxxx.onmicrosoft.com",
          "EditProfilePolicyId": "B2C_1_EditProfile",
          "Instance": "https://xxxx.b2clogin.com/",
          "SignedOutCallbackPath": "/signout/B2C_1_susi",
          "SignUpSignInPolicyId": "B2C_1_SUSI"
      },
      "DownstreamApi": {
          "BaseUrl": "https://localhost:7208/",
          "Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
      }</code></pre>
  </div>
  </div>
  </p>
  <p><strong>WEB API</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"AzureAdB2C": {
      "ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "Domain": "xxxx.onmicrosoft.com",
      "Instance": "https://xxxx.b2clogin.com/",
      "Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
      "SignUpSignInPolicyId": "B2C_1_SUSI"
  }</code></pre>
  </div>
  </div>
  </p>
  <p>After making these changes, I can run the applications and the Web App will attempt to login in through my social accounts then go into an infinite loop redirecting between the login server and the app redirect Url.</p>
  <p>I do get a log message that MicrosoftIdentityWebChallengeUserException was thrown (presumably because I need to consent to the scopes). My understanding is that the <code>[AuthorizeForScopes(ScopeKeySection = &quot;DownstreamApi:Scopes&quot;)]</code> attribute on the Razor page should handle this consent workflow for me, but it doesn't seem to be doing that.</p>
  <p>Is there something additional I need to do in configuring these sample applications or a way to trap the WebChallenge exception (and if so, how do I issue the challenge back to the user)?</p>
  <p>I feel like I am missing something obvious here to get this to work, but I cannot seem to find it.  Can anyone provide some guidance to get this to work?</p>