longfld / aspnetcoreangularjwt Goto Github PK
View Code? Open in Web Editor NEWAngular in ASP.NET Core with JWT solution by systemjs
License: MIT License
Angular in ASP.NET Core with JWT solution by systemjs
License: MIT License
It seems you are setting the expires time based on the local machine time and based on GMT time is what is expected.
Update to the following?
var requestAt = DateTime.UtcNow;
System.ArgumentException occurred
HResult=0x80070057
Message=IDX10401: Expires: '11/02/2017 20:12:57' must be after NotBefore: '11/03/2017 00:32:57'.
Source=
StackTrace:
at System.IdentityModel.Tokens.Jwt.JwtPayload..ctor(String issuer, String audience, IEnumerable1 claims, Nullable
1 notBefore, Nullable1 expires, Nullable
1 issuedAt)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateJwtSecurityTokenPrivate(String issuer, String audience, ClaimsIdentity subject, Nullable1 notBefore, Nullable
1 expires, Nullable`1 issuedAt, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateToken(SecurityTokenDescriptor tokenDescriptor)
at ASPNETCoreAngularJWT.TokenAuthController.GenerateToken(User user, DateTime expires) in D:\Users\Main\Visual Studio 2017\Projects\ASPNETcoreAngularJWT-master\Controllers\TokenAuthController.cs:line 64
at ASPNETCoreAngularJWT.TokenAuthController.Login(User user) in D:\Users\Main\Visual Studio 2017\Projects\ASPNETcoreAngularJWT-master\Controllers\TokenAuthController.cs:line 31
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()
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);
}
Hi,
Your code lacks controller for token issuing.
And not bad to have a sample of usage from JS for example.
Hi,
Could you please explain why the page never loads when debugging. It just shows the index loading page and nothing happens
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.