Giter Site home page Giter Site logo

luckyleonard / nodejs-jwt-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tiagralee/nodejs-jwt-example

1.0 0.0 0.0 6 KB

sample implementation of an authentication system that uses JSON Web Token to manage users' login data in Node.js web server.

JavaScript 100.00%

nodejs-jwt-example's Introduction

NODEJS-JWT-EXAMPLE

This project is a sample implementation of an authentication system that uses JSON Web Token to manage users' login data in Node.js web server.

Express.js, Mongoose, ES6 Syntax is used in this project.

Tutorial on this project is available at https://velopert.com/2448 (KOREAN)

Getting Started

Prerequisites

  • node.js 6.9.x
  • npm 3.x
  • MongoDB 3.0

Installing & Configuration

  1. Install dependencies
npm install
  1. Rename config.example.js to config.js
  2. Get a mongodb server and input mongodbUri of config.js

Run the server

npm start

APIs

Auth Route

Register

POST /api/auth/register

{
    username,
    password
}

Description: creates a new user; first user will be assigned as an admin user. Password is stored in HMAC-SHA1 format

Login

POST /api/auth/login

{
    username,
    password
}

Description: logs in to the server. Server will return a JWT token as:

{
  "message": "logged in successfully",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ODQ4MjU1NjJhOWRlMDE5NmM5MTI4ZmIiLCJ1c2VybmFtZSI6InRlc3RlciIsImFkbWluIjp0cnVlLCJpYXQiOjE0ODExMjMxNjMsImV4cCI6MTQ4MTcyNzk2MywiaXNzIjoidmVsb3BlcnQuY29tIiwic3ViIjoidXNlckluZm8ifQ.vh8LPqxYWJtO6Bxe7reL7sEon13dYFFnhpnyyEmaLBk"
}

Check

GET /api/auth/check or GET /api/auth/check?token={token}

Description: checks the JWT. Token should be passed as Url-encoded query or x-access-token header

User Route

APIs in user routes need admin's permission to process

Check

GET /api/user/list

Description: retrieves all user list

Assign Admin

POST /api/user/assign-admin/:username

Description: assigns admin permission to the given user

License

MIT License.
Copyright (c) 2016 velopert.

nodejs-jwt-example's People

Contributors

velopert avatar

Stargazers

 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.