...
|
...
|
@@ -43,13 +43,10 @@ function paramsToRaw(params) { |
|
|
function AlipayStrategy(options, verify) {
|
|
|
if (typeof options === 'function') {
|
|
|
verify = options;
|
|
|
options = {};
|
|
|
}
|
|
|
options = options || {};
|
|
|
passport.Strategy.call(this);
|
|
|
this.name = 'alipay';
|
|
|
this._verify = verify;
|
|
|
this._options = options;
|
|
|
}
|
|
|
|
|
|
util.inherits(AlipayStrategy, passport.Strategy);
|
...
|
...
|
@@ -63,34 +60,33 @@ AlipayStrategy.prototype.authenticate = function(req, options) { |
|
|
|
|
|
delete query.sign_type;
|
|
|
delete query.sign;
|
|
|
let signString = paramsToRaw(query) + this._options.key;
|
|
|
let signString = paramsToRaw(query) + options.key;
|
|
|
|
|
|
if (signType === 'MD5' && sign !== md5(signString)) {
|
|
|
this.error('alipay callback sign check fail');
|
|
|
this.fail('alipay callback sign check fail');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (req.query.is_success === 'T') {
|
|
|
let user = {
|
|
|
userId: req.query.user_id,
|
|
|
realName: req.query.real_name,
|
|
|
realName: req.query.realName,
|
|
|
email: req.query.email
|
|
|
};
|
|
|
|
|
|
|
|
|
this.success(user, null);
|
|
|
} else {
|
|
|
this.error('alipay login fail');
|
|
|
this.fail(req.error_code);
|
|
|
}
|
|
|
} else {
|
|
|
let params = _.assign(defaultOptions, this._options, options);
|
|
|
let params = _.assign(defaultOptions, options);
|
|
|
let signType = params.sign_type;
|
|
|
let key = params.key;
|
|
|
|
|
|
delete params.sign_type;
|
|
|
delete params.sign;
|
|
|
delete params.key;
|
|
|
let signString = paramsToRaw(params) + key;
|
|
|
let signString = paramsToRaw(params) + options.key;
|
|
|
|
|
|
if (signType === 'MD5') {
|
|
|
params.sign = md5(signString);
|
...
|
...
|
@@ -103,4 +99,3 @@ AlipayStrategy.prototype.authenticate = function(req, options) { |
|
|
exports = module.exports = AlipayStrategy;
|
|
|
|
|
|
exports.Strategy = AlipayStrategy; |
|
|
|
...
|
...
|
|