The solution was installing package Microsoft.IdentityModel.JsonWebTokens according to this. I do not understand how that resolved the issue, as I didn't have to do anything else than install it, but I know that it solved the problem.
Microsoft.IdentityModel.JsonWebTokens