title: IdentityServer4 and integration with signinmanager
body: <p>We are working on an application that uses IdentityServer4, a web api endpoint, a web administration front end, and a mobile application.  We have the web application set up like this</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services) {
          services.AddMvc();
  
          JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
  
          services
              .AddAuthentication(options =&gt; {
                  options.DefaultScheme = "Cookies";
                  options.DefaultChallengeScheme = "oidc";
              })
              .AddCookie("Cookies")
              .AddOpenIdConnect("oidc", options =&gt; {
                  options.SignInScheme = "Cookies";
  
                  options.Authority = "http://localhost:5000";
                  options.RequireHttpsMetadata = false;
  
                  options.ClientId = "mvc";
                  options.ClientSecret = "secret";
                  options.ResponseType = "code id_token";
  
                  options.SaveTokens = true;
                  options.GetClaimsFromUserInfoEndpoint = true;
  
                  options.Scope.Add("api1");
                  options.Scope.Add("offline_access");
              });
      }
  </code></pre>
  
  <p>This works and when we call into a controller that has an [Authorize] attribute on it, we get redirected, sign in, return to the calling site, and all is well.</p>
  
  <p>Now we are trying to add authorization into the mix.  I've seen the video where it is shown not to put authorization information into the token and I get that conceptually.  But now I'd like to do something simple in the UI, like show or hide a link based on if the user is signed in or not.  The default _LoginPartial page has something like this:</p>
  
  <pre><code>@inject SignInManager&lt;User&gt; SignInManager
  @inject UserManager&lt;User&gt; UserManager
  
  @if (SignInManager.IsSignedIn(User)) {
    User is signed in
  } else {
    User is anonymous
  }
  </code></pre>
  
  <p>In order to use SignInManager and UserManager, we'd have to set up the dependency service:</p>
  
  <pre><code>services.AddDbContext&lt;Entities.ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
  services.AddIdentity&lt;User, IdentityRole&lt;long&gt;&gt;()
    .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
    .AddDefaultTokenProviders();
  </code></pre>
  
  <p>But when I do that, it messes up the authorization attribute on the home controller.  </p>
  
  <p>How do I, using IdentityServer4, go about testing whether a user is logged in or not and access my role storage in the web application?  I must be missing something that is allowing us to externally authenticate and then turn around and figure out what roles / claims the user is able to be in / use.</p>