title: Azure AD B2C - Calling function when user signs in
body: <p>I have an MVC Core 2.1 application, and am using Azure AD B2C (2.1.1) as the identity provider.</p>
  
  <p>I want to call a function when a user signs in and signs out, and am guessing I need to put this in the middleware.</p>
  
  <p>In the previous version of the AD B2C, there was a function:</p>
  
  <pre><code>app.UseOpenIdConnectAuthentication(options);
  </code></pre>
  
  <p>which had options that made notification functions available:</p>
  
  <pre><code>Notifications = new OpenIdConnectAuthenticationNotifications
  {
      AuthenticationFailed = this.AuthenticationFailed,
      RedirectToIdentityProvider = this.OnRedirectToIdentityProvider
  }
  </code></pre>
  
  <p>The <code>app.UseOpenIdConnectAuthentication(options);</code> function is now marked as obsolete.</p>
  
  <p>I could put in a middleware call like this:</p>
  
  <pre><code>app.Use((context, next) =&gt;
  {
      if(/*context handler referrer includes "B2C_1_SignUpPolicy"*/)
      {
          // User has signed-in
      }
      return next.Invoke();
  }
  </code></pre>
  
  <p>… but this would be called for every request and cannot be adapted to also call a function when the user signs out.</p>
  
  <p>So do I set up notifications in the <code>app.UseAuthentication();</code> version?</p>