1.0.12 • Published 6 years ago

third-party-login v1.0.12

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
6 years ago

third-party-login

third party login plugin

npm install third-party-login --save

currently available for weibo weixin qq alipay

on todo list github douban taobao jd

usage:

const express = require('express');
const router = express.Router();
    
const config = require("./config");
const login = require("third-party-login");
    
// initialization
login.init(config);
    
// single platform
router.get("/login/weibo", login.weibo.auth);
router.get("/login/callback/weibo", login.weibo.token);
    
// multi-platforms
["weixin", "alipay", "qq"].forEach((key) => {
    router.get(`/login/${key}`, login[key].auth);
    router.get(`/login/callback/${key}`, login[key].token);
}

config:

{
    loadUserInfo: true,
    weibo: {
        redirect: "",
        app: {
            id: "",
            secret: ""
        },
        callbacks: {
            success: (data, req, res, next) => {

            },
            failure: (err, req, res, next) => {

            }
        }
    },
    weixin: {
        redirect: "",
        app: {
            id: "",
            secret: ""
        },
        scope: "snsapi_login",
        callbacks: {
            success: () => {

            },
            failure: () => {

            }
        }
    },
    alipay: {
        redirect: "",
        app: {
            id: ""
        },
        keys: {
            public: "",
            private: ""
        },
        scope: "auth_user",
        callbacks: {
            success: (req, res, next, data) => {

            },
            failure: (req, res, next, err) => {

            }
        }
    }
}

field explain for config

  • Common config

    loadUserInfo: if you want to load user info after you get token. set to true to load user info by token. Or false if uid is all you want.

  • platform config

    redirect: redirect url for platform after user login and authorized.

    app: your developer info of the platform. Get this on your developer's app page of the platform

    • id: app id
    • secret: app secret

      scope: authorize scope

      keys: public key and private key to sign and verify.(alipay only)

    • private: private key you generate by alipay's key tool.(for parameter sign)

    • public: alipay generated public key after you uploaded your public key.(for response verify)

      callbacks: callback function to handle response data

    • success: callback for success response data(token or user info)

    • failure: callback for failed response or error
1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago