title: How to set cookies in asp.net core during authenticaiton/authorization
body: <p>I am trying to set custom cookies during the cookie and openIdConnect authentication/authorization in asp.net core 3.1 but not having any success.  I hope someone can point me in the right direction. Here is my middleware setup:</p>
  <pre><code>        services.AddAuthentication(options =&gt;
          {
              options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
          })
          .AddCookie(option =&gt; {
  
              option.Events = new CookieAuthenticationEvents {
                   //Tried the OnSignedIn() to set the custom cookie but no avail
              }
                  
          })
          .AddOpenIdConnect(&quot;Is4&quot;, options =&gt;
          {
              options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              options.Authority = &quot;identityserver4.url&quot;;
              options.RequireHttpsMetadata = false;
              options.ClientId = &quot;ClientId&quot;;
              options.ClientSecret = &quot;ClientSecret&quot;;
              options.ResponseType = OpenIdConnectResponseType.Code;
              options.UsePkce = true;
              options.ResponseMode = &quot;form_post&quot;;
              options.CallbackPath = &quot;/signin-oidc&quot;;
              options.GetClaimsFromUserInfoEndpoint = true;
              options.Scope.Add(&quot;openid&quot;);
              options.Scope.Add(&quot;profile&quot;);
              options.Scope.Add(&quot;offline_access&quot;);
              options.Scope.Add(&quot;customer-api&quot;); 
             
              options.SaveTokens = true; 
  
              options.Events = new OpenIdConnectEvents
              {
                  OnUserInformationReceived = (context) =&gt;
                  {
                      var accessTokenSplit = context.ProtocolMessage.AccessToken.Split(&quot;.&quot;);
  
                      context.Response.Cookies.Append(
                              key: &quot;HeaderPayload&quot;,
                              value: $&quot;{accessTokenSplit[0]}.{accessTokenSplit[1]}&quot;,
                              options: new CookieOptions
                              {
                                  Domain = &quot;localhost:5001&quot;,
                                  SameSite = SameSiteMode.Strict,
                                  Expires = DateTimeOffset.UtcNow.AddMinutes(30),
                                  Secure = true,
                                  HttpOnly = false
                              }
                          );
  
                      context.Response.Cookies.Append(
                              key: &quot;Signature&quot;,
                              value: $&quot;{accessTokenSplit[2]}&quot;,
                              options: new CookieOptions
                              {
                                  Domain = &quot;localhost:5001&quot;,
                                  SameSite = SameSiteMode.Strict,
                                  Expires = DateTimeOffset.UtcNow.AddMinutes(30),
                                  Secure = true,
                                  HttpOnly = true
                              }
                          );
  
                      return Task.CompletedTask;
                  }
          });
  </code></pre>
  <p>The <code>HeaderPayload</code> and <code>Signature</code> are my custom cookies I want the browser to have at the end of the authentication workflow. Instead I only see .AspnetCore.CookiesC1 and .AspnetCore.CookiesC2.  I guess the cookie authentication middleware is not aware of my custom cookie I set in one of the AddCookie() or AddopenIdConnect() events.  I can however set those cookies in a custom middleware with <code>context.Response.Cookies.Append(...)</code> to show up in the browser but I won't have access to the JWT access token there so would rather handle it in the authentication pipeline.  Any thoughts or suggestions?  Thanks</p>