Coder Social home page Coder Social logo

explorer14 / jwtauthenticationhelper Goto Github PK

View Code? Open in Web Editor NEW
85.0 10.0 30.0 1.28 MB

A simple Json Web Token authentication helper library that allows you to generate access tokens easily for both ASP.NET Core web apps (cookie based auth) and Web APIs (stateless token based auth).

License: GNU General Public License v3.0

C# 98.90% PowerShell 1.10%

jwtauthenticationhelper's Introduction

Introduction

TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.

Getting Started

TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:

  1. Installation process
  2. Software dependencies
  3. Latest releases
  4. API references

Build and Test

TODO: Describe and show how to build your code and run the tests.

Contribute

TODO: Explain how other users and developers can contribute to make your code better.

If you want to learn more about creating good readme files then refer the following guidelines. You can also seek inspiration from the below readme files:

jwtauthenticationhelper'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  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

jwtauthenticationhelper's Issues

I think I found a bug in your code regarding iat in your function **MergeUserClaimsWithDefaultClaims**

I think I found a bug in your code regarding iat in your function MergeUserClaimsWithDefaultClaims

//I think this is incorrect - should be seconds since 1970
new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.TimeOfDay.Ticks.ToString(), ClaimValueTypes.Integer64)

//My fix
long seconds = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
new Claim(JwtRegisteredClaimNames.Iat,seconds.ToString(),ClaimValueTypes.Integer64)

Originally posted by @Weboholics in #1 (comment)

CryptographicException, the payload was invalid

Hi, I followed your example for Jwt cookie authentication. However, I don't know why, but I keep getting an error CryptographicException, the payload was invalid whenever I have a cookie.

Here is my startup config.

        ```
         var appName = "app.myname";

        services.AddDataProtection(options =>
                options.ApplicationDiscriminator =
                    appName)
            .SetApplicationName(
                appName);
        services.AddScoped<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
        
        // Konfiguriramo schemu za authentikaciju.
        services.AddAuthentication(x =>
        {
            x.DefaultAuthenticateScheme =
                CookieAuthenticationDefaults.AuthenticationScheme;
            x.DefaultSignInScheme =
                CookieAuthenticationDefaults.AuthenticationScheme;
            x.DefaultChallengeScheme =
                CookieAuthenticationDefaults.AuthenticationScheme;
        })
            .AddCookie(opt =>
            {
                //opt.TicketDataFormat = JwtAuthTicketFormat.Create(validationParameters, services);
                opt.SlidingExpiration = false;
                opt.Cookie.Name = cookieName;
                opt.LoginPath = "/pmfst/login";
                opt.LogoutPath = "/pmfst/logout";
                opt.AccessDeniedPath = "/pmfst/login";
                opt.ReturnUrlParameter = "/";
               
                opt.TicketDataFormat = new JwtAuthTicketFormat( validationParameters, TicketSerializer.Default, 
                                                                                                                
                    services.BuildServiceProvider().GetDataProtector(new[]
                    {
                        $"{appName}-Auth1"
                    }));
            });



On the other hand, I also keep getting a stackoverflow exception, I believe this is when I don't have a cookie.

NOTE: I don't have a path for logout, but I don't believe that is the issue. 

How to implement Refresh token concept for cookie based auth

Dear @explorer14 ,

i have to implement refresh token concept in my asp.net core 3.1 mvc application to avoid the user to relogin after the token expiration.

as my application is server side mvc, i went with cookie based jwt auth implementation, i need your help to implement the refresh token concept in cookie based jwt auth.

kindly help me to achieve this.

thanks in advance!

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.