Coder Social home page Coder Social logo

angular-jwot-auth's Introduction

Angular JWT Authentication Example

This repo provides a fully implemented reference example of how to implement authentication using JWT tokens, Angular and Express.

Overall Summary Descriptions

Here's several student explanations about what's going on at a high level here:

  • A user makes a request to login, the server authenticates the user. If the user is authenticated the server sends back the user and token. If the user is not authenticated then the server sends an error message as a response. If authenticated (the token passes the secret that’s stored in the dot env) the token is appended to the header of each ajax request. Angular serves up AJAX requests every time a request is made to load a page. We use Auth Interceptors to attach token to the headers of these requests, much like a hook. The response to the client request is based on the token.

  • Log In Process

    1. view: log in button
    2. button controller/service: get authenticate; save JWT token to localStorage
    3. authentication service: store/delete tokens
    4. server: authorization header->each request; configure angular app to use the header
  • Go to login. Email and password sent via ajax. Server checks if password is the correct hash for that email. If authenticated it sends back a token. The token is saved to local storage. Each request to the server from the client is intercepted and a token is added to the request. Each request that requires authorization on the server will make sure there is a token present.

  • you make a request to log in with email and password, if those fields are correct the server sends back a token which is saved in your local storage. then when you navigate through the website the server checks if you have a token and if so, allows you to access otherwise restricted areas. if you logout or leave the page the token is removed from localstorage and it's not sent to the server anymore, so the server will block access to restricted requests.

  • login calls db, if it's true, then send back a token to save on the localStorage.

    Every new request will then send along the the auth token in the header via the intersceptor, and then the routes check for that and then send responses based on if you have the right auth token or not.


Licensing

  1. All content is licensed under a CC-BY-NC-SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

angular-jwot-auth's People

Contributors

geluso 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.