node-token-authentication

Code for the scotch.io tutorial: Authenticate a Node API Using JSON Web Tokens

  • Owner: scotch-io/node-token-authentication
  • Platform:
  • License::
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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
  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 server.js
  6. Create sample user by visiting: http://localhost:8080/setup

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/authenticate 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/users 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/users?token=YOUR_TOKEN_HERE

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

Main metrics

Overview
Name With Ownerscotch-io/node-token-authentication
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:
所有者活动
Created At2014-10-23 22:31:38
Pushed At2017-12-29 12:33:11
Last Commit At2017-10-02 17:32:48
Release Count0
用户参与
Stargazers Count362
Watchers Count19
Fork Count198
Commits Count19
Has Issues Enabled
Issues Count6
Issue Open Count2
Pull Requests Count3
Pull Requests Open Count1
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private