I have been working on gracefully handling token expirations in one of our React app, and so I set the expiry to one minute as follows
new JwtAuthProvider() {
ExpireTokensIn = TimeSpan.FromMinutes(1), // JWT Token Expiry
ExpireRefreshTokensIn = TimeSpan.FromDays(365), // Refresh Token Expiry
UseTokenCookie = false, AllowInQueryString = true, AuthKeyBase64 =
Environment.GetEnvironmentVariable("JWT_KEY")},
}
and cors as follows:
Plugins.Add(new CorsFeature(
allowOriginWhitelist: new[] { "http://localhost:3000"},
allowCredentials: true,
allowedHeaders: "Content-Type, Allow, Authorization, X-Args"));
I clear session cookie storage, the app gets a 401 on the first api call, properly redirects to login, and renders the first page including several api calls.
Wait one minute, and start getting CORS errors as follows:
Browser error:
Access to fetch at ‘https://localhost:5001/json/reply/GetBidsReq’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: The value of the ‘Access-Control-Allow-Credentials’ header in the response is ‘’ which must be ‘true’ when the request’s credentials mode is ‘include’.
Request Headers:
GET /json/reply/GetBidsReq HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Connection: keep-alive
Host: localhost:5001
Origin: http://localhost:3000
Referer: http://localhost:3000/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
authorization: Bearer eyJ0eXAiOiJxxxsRQl8LwD6ut9R663JrJwXRJHW0g8U
content-type: application/json
sec-ch-ua: "Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Response Headers:
HTTP/1.1 200 OK
Content-Length: 40
Date: Tue, 07 Mar 2023 02:00:17 GMT
Server: Kestrel
Access-Control-Allow-Origin: http://localhost:3000