Giter VIP home page Giter VIP logo

jwt-node-express's Introduction

#An Node/Express Example of JWT (JSON Web Tokens)

This simple application is designed to demonstrate the principle of using JWT (JSON Web Tokens) as access tokens to protect an API.

For an overview of how it all works, read the tutorial - to follow shortly.

##Pre-requisites

Obviously you'll need Node and npm, and you also need MongoDB installed and running.

##Installing and Setting Up

Install the project dependencies:

npm install

Ensure Mongod is running, and seed the database:

node seed.js

This will create a single user:

Username: bob

Password: password

##Using It

To use it without a client application, use something like Postman, for Chrome or Poster, for Firefox.

Run the application:

node app.js

To get a token, make a GET request to:

http://localhost:3000/token

You'll need to set the headers:

username : bob

password : password

Make a note of the access token in the returned JSON.

Now try making a GET request to the following URL:

http://localhost:3000/secret

You should get a 401 Not Authorized.

However, if you set the access token; either as a GET parameter access_token or a header called x-access-token you should see the following:

Hello bob

That' it!

jwt-node-express's People

Contributors

lukaswhite avatar

Watchers

 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.