-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from justan/master
Added provider for weibo.com
- Loading branch information
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ var usersByMailchimpId = {}; | |
var usersMailruId = {}; | ||
var usersByMendeleyId = {}; | ||
var usersByDcId = {}; | ||
var usersByWeiboId = {}; | ||
var usersByLogin = { | ||
'[email protected]': addUser({ login: '[email protected]', password: 'password'}) | ||
}; | ||
|
@@ -419,6 +420,16 @@ everyauth | |
(usersByMailchimpId[mailchimpUser.user_id] = addUser('mailchimp', mailchimpUser)); | ||
}) | ||
.redirectPath("/"); | ||
|
||
everyauth | ||
.appId(conf.weibo.appId) | ||
.appSecret(conf.weibo.appSecret) | ||
.findOrCreateUser( function (session, accessToken, accessTokenExtra, weiboUser){ | ||
return usersByWeiboId[weiboUser.uid] || | ||
(usersByWeiboId[weiboUser.uid] = addUser('weibo', weiboUser)); | ||
}) | ||
.redirectPath("/"); | ||
|
||
var app = express.createServer( | ||
express.bodyParser() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
var oauthModule = require('./oauth2') | ||
, querystring= require('querystring') | ||
, request = require('request'); | ||
|
||
var weibo = module.exports = | ||
oauthModule.submodule('weibo') | ||
.configurable({ | ||
scope: "There's no idea about weibo's scope" | ||
}) | ||
|
||
//fetch weibo user needs userid in extra | ||
.step('fetchOAuthUser') | ||
.accepts('accessToken extra') | ||
.promises('oauthUser') | ||
|
||
.oauthHost('https://api.weibo.com') | ||
.apiHost('https://api.weibo.com') | ||
|
||
.authPath('/oauth2/authorize') | ||
.authQueryParam('response_type', 'code') | ||
|
||
.accessTokenPath('/oauth2/access_token') | ||
.accessTokenParam('grant_type', '') | ||
.postAccessTokenParamsVia('data') | ||
|
||
.entryPath('/auth/weibo') | ||
.callbackPath('/auth/weibo/callback') | ||
|
||
.authQueryParam('scope', function () { | ||
return this._scope && this.scope(); | ||
}) | ||
|
||
.getAccessToken( function (code) { | ||
var p = this.Promise() | ||
, url = this._oauthHost + this._accessTokenPath | ||
, opts = { url: url }; | ||
|
||
opts.form = { | ||
client_id: this._appId | ||
, redirect_uri: this._myHostname + this._callbackPath | ||
, code: code | ||
, client_secret: this._appSecret | ||
}; | ||
|
||
request.post( opts, function(err, res, body){ | ||
var data; | ||
if (err) { | ||
p.fail(err); | ||
} else { | ||
data = JSON.parse(body); // sina weibo return a JSON with text/plain | ||
p.fulfill(data.access_token, data); | ||
delete data.access_token; | ||
} | ||
}); | ||
return p; | ||
}) | ||
.fetchOAuthUser( function (accessToken, extra) { | ||
var p = this.Promise(); | ||
var uid = extra.uid; | ||
var url = this.apiHost() + "/2/users/show.json?uid=" + uid; | ||
|
||
this.oauth.get(url, accessToken, function (err, user) { | ||
if (err) { | ||
p.fail(err); | ||
}else{ | ||
p.fulfill(JSON.parse(user)); | ||
} | ||
}); | ||
|
||
return p; | ||
}) | ||
.convertErr( function (err) { | ||
return new Error(err.data ? err.data : err); | ||
}); |