All Projects → supermamon → node-restify-jwt-sample

supermamon / node-restify-jwt-sample

Licence: MIT license
A sample restify api service with JWT authentication

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-restify-jwt-sample

js
serverless your express/koa/restify apps
Stars: ✭ 21 (+23.53%)
Mutual labels:  restify
Apollo Server
🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
Stars: ✭ 12,145 (+71341.18%)
Mutual labels:  restify
Node Restify
The future of Node.js REST development
Stars: ✭ 10,335 (+60694.12%)
Mutual labels:  restify
generator-smacss
Perfectionist generator that scaffolds out different types of Frontend apps
Stars: ✭ 60 (+252.94%)
Mutual labels:  restify
node-typescript-restify
Example Application
Stars: ✭ 26 (+52.94%)
Mutual labels:  restify
HotelManagementSystem
Hotel Management System created with Restify and Angular 9
Stars: ✭ 23 (+35.29%)
Mutual labels:  restify
node-rest-jwt-redis
node restify jwt redis mongo demo
Stars: ✭ 18 (+5.88%)
Mutual labels:  restify
restify-jwt-community
Restify middleware that validates a JsonWebToken
Stars: ✭ 24 (+41.18%)
Mutual labels:  restify
generator-node-api-docker-1st-class-experience
NodeJS + Typescript + TSLint + Restify + MongoDB + Docker, With VS Code Automation = VSCode TypeScript Live Debug with Containers
Stars: ✭ 22 (+29.41%)
Mutual labels:  restify

node-restify-jwt-sample

A sample api service with JWT authentication

What's Inside

  • route path prefix
  • versioned routes
  • protected/unprotected routes
  • registration
  • admin/non-admin routes
  • logging (using winston)
  • unit tests

Configure

See /config/index.js

Examples

Use api/register to generate tokens.

$ curl -X POST \
> -H "Content-Type: application/json" \
> --data '{ "name": "Johnny Appleseed", "role": "test", "password":"some-hashed-password" }' \
http://localhost:8080/api/register

{"name":"Johnny Appleseed","role":"test","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obm55IEFwcGxlc2VlZCIsInJvbGUiOiJ0ZXN0IiwiaWF0IjoxNTA5MDc2MTEwfQ.EsRsidT33amgeDX8u6SlE6LwWUs2jpyblogOvLaJ1Y8"}

$ curl -X POST \
> -H "Content-Type: application/json" \
> --data '{ "name": "Tim Cook", "role": "admin", "password":"some-hashed-password" }' \
http://localhost:8080/api/register

{"name":"Tim Cook","role":"admin","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVGltIENvb2siLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE1MDkwNzY0NzB9.f5_v9HfOAiOS4IiiQ5Pj0IxLOMJGWUhHQ57Zd9opqwE"}

Route protection

$ curl localhost:8080/api/ping
{"ping":"OK"}

$ curl localhost:8080/api/home
{"code":"InvalidCredentials","message":"No authorization token was found"}

Protected route

$ curl -H "Authorization: Bearer your-token" localhost:8080/api/home
{"welcome":"Johnny Appleseed"}

Admin route

$ curl -H "Authorization: Bearer admin-token" localhost:8080/api/admin
{"action":"completed"}

$ curl -H "Authorization: Bearer user-token" localhost:8080/api/admin
{"code":"Forbidden","message":"You don't have sufficient priviledges."}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].