Last night I spent a few hours trying to figure out what is wrong with my JWT token as I was getting
401 Error when I try to access my Apis when I run them locally in Docker for Windows
when I click the response header I saw
WWW-Authenticate : Bearer error=”invalid_token”, error_description=”The token is not valid yet”
I got in to full diagnose mode to understand what is going on,
I start running Postman requests,
the app runs fine in AKS with the same JWT token,
the app runs fine when I run it locally on my machine (not in docker just dotnet run on my laptop) with the same JWT
The token is not valid yet, I had experienced something like this before on my Ops days when date-time between PCs were out of whack. I added a method to a controller to justify my suspicion
[Route("datenow")] public string DateNow() { return DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); }
and got back “Thursday, 29 August 2019 11:08:24”
When for Linux containers, docker for Windows runs a Virtual Machine to supply the Linux (you can also run Windows Containers config and run Linux images with as windows subsystem too)
in my case, date-time sync is not working. I open Hyper-V Manager
Select DockerDesktopVM (in old system name was MobyLinuxVM) right click and Select Settings
click Integration Services from the left menu, if Time synchronization not checked, check it and click Apply and OK,
if it is Checked, first unchecked Time synchronization click Apply, Check again Time synchronization Apply Again and Click OK.
when I run the time method again “Monday, 02 September 2019 11:20:22” I got the right time and authentication start working again.