【发布时间】:2015-11-28 05:46:31
【问题描述】:
我在 node.js 应用程序中实现 Oauth2 身份验证时遇到问题,我需要在授权请求中添加一个额外参数,但模块只是忽略了“未知”参数。
我的代码附在下面。被忽略的参数是APIName。
var OAuth2Strategy = require('passport-oauth2').Strategy;
// load the auth variables
var configAuth = require('./auth');
module.exports = function(passport) {
passport.use('ihealth', new OAuth2Strategy({
authorizationURL: 'https://api.ihealthlabs.com:8443/OpenApiV2/OAuthv2/userauthorization/',
tokenURL: 'https://api.ihealthlabs.com:8443/OpenApiV2/OAuthv2/userauthorization/',
clientID: configAuth.iHealthAuth.clientID,
clientSecret: configAuth.iHealthAuth.clientSecret,
callbackURL: configAuth.iHealthAuth.callbackURL,
APIName : 'OpenApiActivity'
},
function(token, refreshToken, profile, done) {
// ...
}
));
};
我知道APIName 被忽略的原因是我在浏览器中看到了 URL:
https://api.ihealthlabs.com:8443/OpenApiV2/OAuthv2/userauthorization/?response_type=code&redirect_uri=SOMEREDIRECTURI&client_id=SOMECLIENTID
我想知道如何启用向授权请求添加额外参数?也许通过覆盖node_modules/passport_oauth2/lib/strategy.js 中的函数OAuth2Strategy.prototype.authorizationParams,在下载的文件中看起来像这样:
/**
* Return extra parameters to be included in the authorization request.
*
* Some OAuth 2.0 providers allow additional, non-standard parameters to be
* included when requesting authorization. Since these parameters are not
* standardized by the OAuth 2.0 specification, OAuth 2.0-based authentication
* strategies can overrride this function in order to populate these parameters
* as required by the provider.
*
* @param {Object} options
* @return {Object}
* @api protected
*/
OAuth2Strategy.prototype.authorizationParams = function(options) {
return {};
};
【问题讨论】:
标签: javascript node.js oauth-2.0