Giter VIP home page Giter VIP logo

pose_jwt_demo's Introduction

JWT Demo

Typically, you want your applications to use OIDC providers to allow your users to 'login with GitHub' and similar services. That is because security is hard and logins/user data has to be secure.

In an enterprise environment you would probably use something like a dedicated KeyCloak instance (as we do as well) or Microsoft Entra for AD integration etc.

However, for some small project you may still want to do local accounts. And even if you use an external service you should still understand how things work and what is going on in the background. Make sure you read the comments in the code, they give valuable insights and hints.

This demo project shows you:

  • For the backend:

    • Adding new users

      • With hashed passwords etc.

    • Creating JWT tokens

      • With user claims, based on their roles

      • Storing access and refresh tokens in a database

        • And removing them when expired or user logs out

    • Applying rate limiting for the login endpoint

    • Validating JWT tokens

    • Policies

      • Creating policies for different roles

      • Securing endpoints with policies

    • Providing a SignalR hub which checks for user auth state

  • For the frontend:

    • Login & Logout

    • Storing access and refresh tokens in local storage

    • Automatically applying bearer token to requests

      • Except for auth requests, which can (should) not have them

    • Role based auth guard for routes

    • Automatically refreshing tokens

    • Using token with SignalR connection

Caution
As mentioned before, security is hard, and for this demo some shortcuts have been taken. You may use it as a starting point, but don’t deploy it as is!

pose_jwt_demo's People

Contributors

markushaslinger avatar

Stargazers

Jonas Hinterdorfer avatar

Watchers

 avatar

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.