-
Notifications
You must be signed in to change notification settings - Fork 653
/
CookieHandler.cs
26 lines (23 loc) · 1009 Bytes
/
CookieHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using Microsoft.AspNetCore.Components.WebAssembly.Http;
namespace BlazorWasmAuth.Identity
{
/// <summary>
/// Handler to ensure cookie credentials are automatically sent over with each request.
/// </summary>
public class CookieHandler : DelegatingHandler
{
/// <summary>
/// Main method to override for the handler.
/// </summary>
/// <param name="request">The original request.</param>
/// <param name="cancellationToken">The token to handle cancellations.</param>
/// <returns>The <see cref="HttpResponseMessage"/>.</returns>
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// include cookies!
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
request.Headers.Add("X-Requested-With", ["XMLHttpRequest"]);
return base.SendAsync(request, cancellationToken);
}
}
}