Code Monkey home page Code Monkey logo

authentication's Introduction

Authentication

Notes on authentication - how to think about it and what options are available

What is it?

Authentication is the process of verifying that a user is who he/she says she is (note that this is different than authorization which determines if a user is allowed to access a resource).

Best practice

Current best practice - use JWT (https://jwt.io/introduction/) Try to use an existing framework. Do not make your own authentication scheme - it is harder than you think. For front end use this NPM https://www.npmjs.com/package/jsonwebtoken (npm install --save jsonwebtoken)

Authentication overview

Basic flow

  1. Enter your credentials (username or email and password)
  2. Make HTTPS request containing this data to backend
  3. Check that username and password match
  4. Return user id and any other data and store token in LocalStorage

LocalStorage

About LocalStorage (https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) Tokens stored in LocalStorage are DOMAIN SPECIFIC - that means "stuff" stored in LocalStorage for Facebook.com is not visible to Google.com The token will remain in storage (not the user profile)

Backend endpoints required

/your_app/auth/email - first request to get token

Using bcrypt (encryption to store your passwords securely in database)
https://www.npmjs.com/package/bcrypt-nodejs

Encoding and decoding JWTs
https://github.com/auth0/node-jsonwebtoken

Storing JWT web toekns
https://github.com/grevory/angular-local-storage

Implementation

  • NOTE that every request to your app MUST be authenticated - how do we do this? Include the token in headers of every request (more info about headers - http://stackoverflow.com/questions/1268673/set-a-request-header-in-javascript)

  • Check that the token is valid on every request

  • If the token is valid allow the request (return status code 200)

  • If the token is not valid - do not allow the request to continue and return the appropriate response code (on the front end redirect the user to the login page so that they can try again)

Other resources

authentication's People

Contributors

remarcmij avatar tkaria avatar

Watchers

 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

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.