GithubHelp home page GithubHelp logo

longfld / aspnetcoreangularjwt Goto Github PK

View Code? Open in Web Editor NEW
46.0 10.0 21.0 120 KB

Angular in ASP.NET Core with JWT solution by systemjs

License: MIT License

C# 40.82% TypeScript 38.45% CSS 1.76% JavaScript 11.14% HTML 7.83%
angular bearer token authentication jwt dotnetcore systemjs bear-jwt middleware bearer-tokens

aspnetcoreangularjwt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcoreangularjwt's Issues

Token being generated based on Machine time, needs to be based on GMT time

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, Nullable1 notBefore, Nullable1 expires, Nullable1 issuedAt)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateJwtSecurityTokenPrivate(String issuer, String audience, ClaimsIdentity subject, Nullable1 notBefore, Nullable1 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()

Error Generating Token

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);
        }

controller for a token

Hi,

Your code lacks controller for token issuing.
And not bad to have a sample of usage from JS for example.

Doesn't work in Vs2017

Hi,

Could you please explain why the page never loads when debugging. It just shows the index loading page and nothing happens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.