Skip to content

caiya/node-token-authentication-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Token Authentication

This repo uses JSON Web Tokens and the jsonwebtoken package to implement token based authentication on a simple Node.js API.

This is a starting point to demonstrate the method of authentication by verifying a token using Express route middleware.

Requirements

  • node and npm

Usage

  1. Clone the repo: git clone git@github.com:scotch-io/node-token-authentication-api
  2. Install dependencies: npm install
  3. Change SECRET in config.js
  4. Add your own MongoDB database to config.js
  5. Start the server: node cluster.js
  6. Create sample user by visiting: http://localhost:8080/signup

Once everything is set up, we can begin to use our app by creating and verifying tokens.

Getting a Token

Send a POST request to http://localhost:8080/api/authorize with test user parameters as x-www-form-urlencoded.

  {
    name: 'Nick Cerminara',
    password: 'password'
  }

Verifying a Token and Listing Users

Send a GET request to http://localhost:8080/api/user with a header parameter of x-access-token and the token.

You can also send the token as a URL parameter: http://localhost:8080/api/user?token=YOUR_TOKEN_HERE

Or you can send the token as a POST parameter of token.

Releases

No releases published

Packages

No packages published