qnode-package

### Use with Express

No update
Last updated a year ago by nopbongdem .
MIT · Original npm · Tarball · package.json
$ cnpm install qnode-package 
SYNC missed versions from official npm registry.

WSO Middleware

Use with Express

  • Install
yarn add qnode-package
  • Create wso.js
// sso.js
const { jwtAuth } = require('qnode-package');

module.exports = new jwtAuth({
    userInfoUrl: '', // Required
    clientId: '', // Required
    clientSecret: '', // Required
    accessTokenUri: '', // Required
    authorizationUri: '', // Required
    redirectUri: '', // Required
    ssoProperty: 'email',
    authProperty: 'user', // Will append to req
    secret: 'custom secret',
    tokenModel: {
        saveToken: async (data = {}) => {
            const { access_token, refresh_token, id_token } = data;
            // Save token to DB
        },

        getToken: async token => {
            // Get Token
        },

        getRefreshToken: async token => {
            // Get refresh token by token
        },

        removeToken: async token => {
            // Remove token
        },

        getUser: async email => {
            // get user by ssoProperty
        }
    }
});
  • Use
const express = require('express');
const sso = require('./sso');

const app = express();

// Lấy thông tin người dùng qua token
app.use(sso.authenticated({credentialsRequired:false}), (req, res) => {
    return res.json({
        isAuthenticate: req.isAuthenticate,
        user: req.user
    });
});

// Bắt buộc người dùng phải đăng nhập
app.use(sso.authenticated(), (req, res) => {
    return res.json({
        isAuthenticate: req.isAuthenticate,
        user: req.user
    });
});

// Refresh token
/**
 * Body {refresh_token: string}
 **/
app.post('/refresh-token', sso.refreshToken({ algorithm: 'HS256' }), (req, res) => {
    return res.json({
        token: req.token
    });
});

// Get token
/**
 * Body {code: string}
 **/
app.post('/token', sso.token({ algorithm: 'HS256' }), (req, res) => {
    return res.json({
        token: req.token
    });
});

## Something ...

Current Tags

  • 2.0.3                                ...           latest (a year ago)

8 Versions

  • 2.0.3 [deprecated]           ...           a year ago
  • 2.0.2 [deprecated]           ...           a year ago
  • 2.0.1 [deprecated]           ...           a year ago
  • 2.0.0 [deprecated]           ...           a year ago
  • 1.0.4 [deprecated]           ...           a year ago
  • 1.0.2 [deprecated]           ...           a year ago
  • 1.0.1 [deprecated]           ...           a year ago
  • 1.0.0 [deprecated]           ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |