🚀 DAY 2 OF LAUNCH WEEK: Unify Your Security Stack with Socket Basics.Learn more
Socket
Book a DemoInstallSign in
Socket

passport-qq2015

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-qq2015

qq authentication strategy for Passport.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

passport-qq2015

QQ第三方授权登录,使用与web网站,可在express和koa等框架中使用。 代码用到了Object.assign(),需要在 es6 的环境中使用。

Install

$ npm install passport

项目文件结构

整个项目采用MVC架构,基本项目结构如下图

passport-qq2015/             项目根目录
├── lib/                     核心代码           
├── package.json			 npm的声明文件,包含项目的依赖等
└── README.md				包含对此此项目的一些介绍,就是当前说看到的内容

Usage

配置strategy


  passport.use('qq-token', new qqStrategy({
    clientID: config.qq.appID,
    clientSecret: config.qq.appKEY,
    callbackURL: 'http://www.xxxx.com/auth/token/qq/callback'
  },
    function (accessToken, refreshToken, profile, done) {
      if (!profile) {
        return done(null, false);
      }

      return done(null, profile);
    }
  ));

授权请求

包含两个api接口。第一个请求负责跳转到授权页面,第二个请求是qq授权的回调地址,根据获得的code,依次获得accessToKen, openId, userInfo,并最终跳转到指定的地址。

example如下:


  router.get('/token/qq', passport.authenticate('qq-token', {
    session: false
  }));

  router.get('/token/qq/callback',
    passport.authenticate('qq-token', {
      session: false,
      failureRedirect: 'http://www.fail.com'
    }),
    function *() {
      const res = this.response;
      res.redirect('http://success.com');
    });

Keywords

QQ

FAQs

Package last updated on 24 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts