• Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Using oauth2-server: 3.0.0-b2 & Supports MongoDB, MySQL, PostgreSQL, MSSQL & SQLite

Node OAuth2 Server Implementation

Please refer this Fully functional OAuth 2.0 Implementation with production example with node-oauth2-server#2.4.0

Supports "oauth2-server": "^3.0.0-b2",

Installation

git clone https://github.com/manjeshpv/node-oauth2-server-implementation
npm install
npm start or node ./bin/www

Quick Start

The module provides two middlewares, one for authorization and routing, another for error handling, use them as you would any other middleware:

var express = require('express');
var oauthServer = require('oauth2-server');
var Request = oauthServer.Request;
var Response = oauthServer.Response;
var authenticate = require('./components/oauth/authenticate')

var app = express();

app.use(bodyParser.urlencoded({ extended: true }));

app.use(bodyParser.json());

// https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/models.js
var oauth = new oauthServer({
  model: require('./models.js')
});

app.all('/oauth/token', function(req,res,next){
    var request = new Request(req);
    var response = new Response(res);

    oauth
      .token(request,response)
      .then(function(token) {
        // Todo: remove unnecessary values in response
        return res.json(token)
      }).catch(function(err){
        return res.status( 500).json(err)
      })
  });

  app.post('/authorise', function(req, res){
    var request = new Request(req);
    var response = new Response(res);

    return oauth.authorize(request, response).then(function(success) {
        res.json(success)
    }).catch(function(err){
      res.status(err.code || 500).json(err)
    })
  });

app.get('/secure', authenticate(), function(req,res){
  res.json({message: 'Secure data'})
});

app.get('/me', authenticate(), function(req,res){
  res.json({
    me: req.user,
    messsage: 'Authorization success, Without Scopes, Try accessing /profile with `profile` scope',
    description: 'Try postman https://www.getpostman.com/collections/37afd82600127fbeef28',
    more: 'pass `profile` scope while Authorize'
  })
});

app.get('/profile', authenticate({scope:'profile'}), function(req,res){
  res.json({
    profile: req.user
  })
});

app.listen(3000);

After running with node, visting http://127.0.0.1:3000 should present you with a json response saying your access token could not be found.

To simulate, Use Postman: https://www.getpostman.com/collections/37afd82600127fbeef28

Features

  • Supports authorization_code, password, refresh_token, client_credentials and extension (custom) grant types
  • Implicitly supports any form of storage e.g. PostgreSQL, MySQL, Mongo, Redis...
  • Full test suite

Model Specification

See SQL file in /sql folder

The module requires a model object through which some aspects or storage, retrieval and custom validation are abstracted. The last parameter of all methods is a callback of which the first parameter is always used to indicate an error.

Note: see https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/models.js for a full model example using MySQL.

References: https://github.com/dsquier/oauth2-server-php-mysql

More Repositories

1

node-express-passport-mysql

Login Express + Passport + MySQL
JavaScript
402
star
2

node-restify-mysql-sequelize

JavaScript
8
star
3

minio-nodejs-angularjs-example

Minio Example with Express.js
JavaScript
6
star
4

json.hpack

Nodejs Implementation of https://raw.githubusercontent.com/WebReflection/json.hpack/master/src/javascript/json.hpack.js
JavaScript
4
star
5

wso2-jwt-verify

jsonwebtoken jwt.verify() not worked for me. When token signed from WSO2 API Gateway JWT(Java)
JavaScript
4
star
6

passport-local-express4-mongoose-example

Express 4 Authentication with Passport, Mongoose
JavaScript
4
star
7

sequelize-query-execution-time

sequelize query execution time in http response headers
JavaScript
3
star
8

awesome-fullstack-sandbox

Cloud Native Docker Sandbox for Indian Startups
2
star
9

slim-jwt-auth-demo

JSON Web Token Authentication for Slim Framework Sample Demo
PHP
2
star
10

swagger-hybrid

swagger-ui & swagger-editor for developers http://swagger-hybrid.herokuapp.com/ui/auth
HTML
2
star
11

Provisional-Marks-Card-Generator

Sri Siddhartha Institute of Technology SSIT Tumkur SGPA
PHP
1
star
12

ssit360.github.io

SSIT Developers Home
1
star
13

unsolved-problems

Those Architectural Challenges remain unsolved
1
star
14

redis-plus-lru-cache

Redis + LRU Cache
JavaScript
1
star
15

aloak

1
star
16

nodejs-docker-caprover

CapRover Nodejs Example
JavaScript
1
star
17

gsuite-google-calendar-api-limits

JavaScript
1
star
18

mean-development-guide-2021

Mongo/MySQL/Node/Express/
JavaScript
1
star
19

oauth2-server2

JavaScript
1
star
20

geo-bangalore

1
star
21

node-webhooks-dashboard

Dashboard for Developers - https://github.com/roccomuso/node-webhooks
1
star