title: How to programmatically redirect to Azure AD sign-in and sign-out pages in ASP.NET Core MVC?
body: <p>My ASP.NET Core 2.2 MVC app is using Azure AD to authenticate users. In startup.cs I added Azure AD:</p>
  
  <pre><code>services
    .AddAuthentication(AzureADDefaults.AuthenticationScheme)
    .AddAzureAD(options =&gt; Configuration.Bind("AzureAd", options));
  
  services.Configure&lt;OpenIdConnectOptions&gt;(AzureADDefaults.OpenIdScheme, options =&gt;
  {
    options.Authority = options.Authority + "/v2.0/";
    options.TokenValidationParameters.NameClaimType = "preferred_username";
  });
  </code></pre>
  
  <p>Authorization is done by a policy check:</p>
  
  <pre><code>services.AddAuthorization(options =&gt;
  {
      options.AddPolicy("AdministratorOnly", policy =&gt; {
        policy.RequireClaim("groups", adminGroupId);
    });
  });
  </code></pre>
  
  <p>In appsettings.json I have all the required configuration:</p>
  
  <pre><code>"AzureAd": {
      "Instance": "https://login.microsoftonline.com/",
      "TenantId": "662f1be2-...",
      "ClientId": "30eb6c27-...",
      "CallbackPath": "/signin-oidc",
      "SignedOutCallbackPath ": "/signout-callback-oidc"
  }
  </code></pre>
  
  <p>If I try to access a controller decorated with <code>[Authorize(Policy = "AdministratorOnly")]</code> it will redirect to Azure AD and handle the login process and eventually redirect back to my app.</p>
  
  <p>Questions:</p>
  
  <ul>
  <li>Is there a prescribed to kick off the login process (preferably in a popup window)? Where do I get the URL from to redirect to?</li>
  <li>How can I provide a button to let users logout again? If I redirect to "/signout-oidc" I'm getting signed out but I end up on a blank page.</li>
  </ul>