Error Generating Token
soixantseize opened this issue · 1 comments
soixantseize commented
Thank you for sharing this project. I was having trouble generating a token and getting the following error:
System.ArgumentException: IDX10401: Expires: '04/13/2017 15:10:15' must be after NotBefore: '04/13/2017 18:30:23'.
I added a new NotBefore SecurityTokenDescriptor and it fixed the problem. New GenerateToken method in TokenAuthController.cs:
private string GenerateToken(ApplicationUser user, DateTime expires)
{
var handler = new JwtSecurityTokenHandler();
ClaimsIdentity identity = new ClaimsIdentity(
new GenericIdentity(user.Email, "TokenAuth"),
new[] { new Claim("ID", user.Email.ToString())}
);
var securityToken = handler.CreateToken(new SecurityTokenDescriptor
{
Issuer = TokenAuthOption.Issuer,
Audience = TokenAuthOption.Audience,
SigningCredentials = TokenAuthOption.SigningCredentials,
Subject = identity,
**NotBefore = DateTime.Now,**
Expires = expires
});
return handler.WriteToken(securityToken);
}
Longfld commented
private string GenerateToken(ApplicationUser user, DateTime expires)
I am not sure ApplicationUser : user in GenerateToken method, I have my User class