All Projects → zhulinwei → L Passport

zhulinwei / L Passport

Koa middleware and api sdk for wechat oauth, qq oauth, baidu oauth and weibo oauth

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to L Passport

Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
Stars: ✭ 1,026 (+1873.08%)
Mutual labels:  baidu, qq, oauth, wechat, weibo
Diplomat
整合第三方 SDK 微信、微博、 QQ 等为统一的 Diplomat 接口。
Stars: ✭ 672 (+1192.31%)
Mutual labels:  qq, wechat, weibo
Lcactionsheet
一款简约而不失强大的 ActionSheet,微博、微信和 QQ 都采用了极其类似的样式,完全支持 Swift。
Stars: ✭ 809 (+1455.77%)
Mutual labels:  qq, wechat, weibo
Socialsdklibrary
提供微博、微信、QQ、Tim、QQ 轻聊版、钉钉的登陆分享功能支持;
Stars: ✭ 399 (+667.31%)
Mutual labels:  qq, wechat, weibo
Monkeyking
MonkeyKing helps you to post messages to Chinese Social Networks.
Stars: ✭ 2,699 (+5090.38%)
Mutual labels:  qq, wechat, weibo
Sdk3rd
第三方SDK集成库,授权/分享/支付
Stars: ✭ 249 (+378.85%)
Mutual labels:  qq, wechat, weibo
Web Oauth App
第三方登录服务 Web OAuth 示例
Stars: ✭ 30 (-42.31%)
Mutual labels:  baidu, qq, weibo
Sns auth
通用第三方登录SDK,支持微信,微信扫码,QQ,微博登录,支付宝登录,Facebook,Line,Twitter,Google
Stars: ✭ 520 (+900%)
Mutual labels:  qq, wechat
Deepin Apps Installation
本仓库介绍如何在基于Ubuntu的系统上安装Deepin移植的软件。This repo shows how to install apps packaged by Deepin.
Stars: ✭ 565 (+986.54%)
Mutual labels:  qq, wechat
Ocbarrage
iOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!
Stars: ✭ 589 (+1032.69%)
Mutual labels:  qq, wechat
Grant
OAuth Proxy
Stars: ✭ 3,509 (+6648.08%)
Mutual labels:  koa, oauth
Chord
Chord - A Modern Music Player
Stars: ✭ 615 (+1082.69%)
Mutual labels:  baidu, qq
Fw Cloud Framework
基于springcloud全家桶开发分布式框架(支持oauth2认证授权、SSO登录、统一下单、微信公众号服务、Shardingdbc分库分表、常见服务监控、链路监控、异步日志、redis缓存等功能),实现基于Vue全家桶等前后端分离项目工程
Stars: ✭ 717 (+1278.85%)
Mutual labels:  oauth, wechat
Okam
Mini program development framework
Stars: ✭ 399 (+667.31%)
Mutual labels:  baidu, wechat
Wechat Jssdk
🐧WeChat JS-SDK integration with NodeJS
Stars: ✭ 571 (+998.08%)
Mutual labels:  oauth, wechat
Xiaofendui
薅羊毛小分队(第一时间尽知羊毛)- 微信机器人即时推送
Stars: ✭ 356 (+584.62%)
Mutual labels:  wechat, weibo
Tbactionsheet
A Custom&Powerful Action Sheet For iOS. 一个 ActionSheet 满足所有样式!超高自由度的可定制!
Stars: ✭ 942 (+1711.54%)
Mutual labels:  qq, wechat
Go jwt
golang for websocket wechat or weixin and jwt,http ratelimit
Stars: ✭ 19 (-63.46%)
Mutual labels:  oauth, wechat
Gopay
QQ、微信(WeChat)、支付宝(AliPay)的Go版本SDK。【微信支付V3已支持,推荐使用微信V3接口】
Stars: ✭ 1,034 (+1888.46%)
Mutual labels:  qq, wechat
Ocbarrage
iOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!
Stars: ✭ 294 (+465.38%)
Mutual labels:  qq, wechat

l-passport

集成微信(wechat)、QQ(qq)、百度(baidu)和微博(weibo)于一体的koa中间件与API SDK

功能列表

  • OAuth授权
  • 获取用户基本信息

koa2中间件,开发者可以通过此中间件获取用户的基本信息(包括用户编号、昵称、头像)

Installation

npm install l-passport -S

Usage

Authentication

引入l-passport并配置

const passport = require('l-passport');

// 微信登录:设置appId与app secret
passport.initialize({
  provider: 'wechat'
  appId: 'your_app_id',
  appSecret: 'your_app_secret'
});

router.get('/login/wechat', passport.authorization('wechat'), async (ctx) => {
  ctx.body = ctx.state.passport;
});

如果需要配置多个平台(如web、ios、android),建议参考如下代码

const passport = require('l-passport');

passport.initialize({
  provider: 'wechat', 
  clients: [
    { platform: 'web', appId: 'your_app_id', appSecret: 'your_app_secret' },
    { platform: 'ios', appId: 'your_app_id', appSecret: 'your_app_secret' },
    { platform: 'android', appId: 'your_app_id', appSecret: 'your_app_secret' },
  ]
});

router.get('/login/wechat_web', passport.authorization('wechat', { platform: 'web' }), async (ctx) => {
  ctx.body = ctx.state.passport;
});

router.get('/login/wechat_ios', passport.authorization('wechat', { platform: 'ios' }), async (ctx) => {
  ctx.body = ctx.state.passport;
});

router.get('/login/wechat_android', passport.authorization('wechat', { platform: 'android' }), async (ctx) => {
  ctx.body = ctx.state.passport;
});

如果需要配置多个服务提供商与多个平台,建议参考如下代码

const passport = require('l-passport');

passport.initialize([
  {
    provider: 'wechat', 
    clients: [
      { platform: 'web', appId: 'your_app_id', appSecret: 'your_app_secret' },
      { platform: 'ios', appId: 'your_app_id', appSecret: 'your_app_secret' },
      { platform: 'android', appId: 'your_app_id', appSecret: 'your_app_secret' },
    ]
  },
  {
    provider: 'baidu', 
    clients: [
      { platform: 'web', appId: 'your_app_id', appSecret: 'your_app_secret', redirect: 'your_baidu_redirect' },
      { platform: 'ios', appId: 'your_app_id', appSecret: 'your_app_secret', redirect: 'your_baidu_redirect'},
      { platform: 'android', appId: 'your_app_id', appSecret: 'your_app_secret', redirect: 'your_baidu_redirect' },
    ]
  }
]);

router.get('/login/wechat_web', passport.authorization('wechat', { platform: 'web' }), async (ctx) => {
  ctx.body = ctx.state.passport;
});

router.get('/login/baidu_ios', passport.authorization('baidu', { platform: 'ios' }), async (ctx) => {
  ctx.body = ctx.state.passport;
});

配置参数说明:

  • provider: - 服务提供商(必选)
    • 当前可选:qq、baidu、weibo、wechat
  • appId: - 应用编号(必填)
  • appSecret: - 应用秘钥(必填)
  • platform: - 服务平台(选填)
  • redirect: - 应用回调地址(选填)
  • scope: - 申请的权限范围(选填)
  • state: - 应用当前状态,可以指定任意值,服务提供商会原封不动地返回这个值(选填)

Authentication Url

注意:不同的服务提供商之间,在认证时对回调地址的处理方式各不相同,如微信不会检查回调函数,微博和QQ只需核查回调函数的域名,而百度则需要核查包括Query参数在内的整个回调地址

l-passport支持两种方式设置回调函数

1.配置设置

const passport = require('l-passport');

passport.initialize({
  provider: 'baidu'
  appId: 'your_app_id',
  appSecret: 'your_app_secret',
  redirect: 'your_app_redirect',
  state: 'your_app_state',
  scope: 'your_app_scope'
});

router.get('/login/baidu', passport.authorization('baidu'), async (ctx) => {
  ctx.body = ctx.state.passport;
});

2.动态设置

将redirect、state、scope放在路由的Query参数中,如/login/baidu?redirect=your_redirect&state=your_state&scope=your_scope

拓展登录策略

l-passport已经集成如下:

  • 1.qq:QQ登录
  • 2.baidu:百度登录
  • 3.weibo:微博登录
  • 4.wechat:微信登录

如果开发者觉得当前集成的登录策略无法满足需求时,可以自行拓展,其基本形式如下:

class YourStragety {
  // 服务提供商提供的授权地址  
  getAuthorizeUrl(redirect, state, scope) {}

  // 用户通过授权后的认证过程
  authorize(code) {}
}

passport.use('your_stagety_name', YourStragety);

用户信息格式

认证完成后用户信息将挂载ctx.state.passport中,其基本格式如下:

{
  "provider": "服务提供商",
  "uid"     : "用户编号",
  "nickname": "用户昵称",
  "avatar"  : "用户头像",
  "body"    : {}
}
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].