Giter Club home page Giter Club logo

aliyun-oauth's Introduction

aliyun-oauth

Aliyun OAuth for ES6

Installation

$ npm install aliyun-oauth --save

Documentation

文档地址: http://doxmate.cool/JacksonTian/aliyun-oauth/index.html

Usage

var config = require('../config');
var OAuth = require('aliyun-oauth');
var oauth = new OAuth(config.oauth.key, config.oauth.secret);

// 路由 /login
exports.login = function *() {
  if (this.session.user) {
    this.redirect('/');
    return;
  }

  var callbackUrl = "http://your.domain.com/callback";
  var requestToken = yield* oauth.requestToken(callbackUrl);
  this.session.oauth_token_secret = requestToken.oauth_token_secret;
  var authUrl = oauth.getAuthUrl(requestToken.oauth_token);
  // 跳转去auth/
  this.redirect(authUrl);
};

// 路由 /callback
exports.callback = function * () {
  var query = this.query;
  var token = query.oauth_token;
  var verifier = query.oauth_verifier;
  var secret = this.session.oauth_token_secret;
  // 获取access token
  var accessToken = yield* oauth.getAccessToken(token, verifier, secret);
  this.session.oauth_token = accessToken.oauth_token;
  this.session.oauth_token_secret = accessToken.oauth_token_secret;

  var user = yield* oauth.aliyunid_kp(accessToken.oauth_token, accessToken.oauth_token_secret);
  this.session.user = user;
  this.redirect('/');
};
// 退出时请清理session即可

License

The MIT license

aliyun-oauth's People

Contributors

jacksontian avatar qingyang1014 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.