ExpressJS和passport-linkedin-oauth2无法进行身份验证

时间:2015-01-13 13:05:27

标签: node.js oauth linkedin passport.js

我试图用一个简单的例子来使用passport-linkedin-oauth2然后遇到这个问题:

这是服务器端的日志:

{ [CastError: Cast to number failed for value "XXXXXX" at path "oauthID"]
message: 'Cast to number failed for value "XXXXXX" at path "oauthID"',
name: 'CastError',
type: 'number',
value: 'XXXXXX',
path: 'oauthID' }

这是客户端的错误日志:

TokenError: missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired
at Strategy.OAuth2Strategy.parseErrorResponse (/Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/lib/strategy.js:298:12)
at Strategy.OAuth2Strategy._createOAuthError (/Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/lib/strategy.js:345:16)
at /Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/lib/strategy.js:171:43
at /Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9)
at IncomingMessage.<anonymous> (/Users/percevio/projects/web-learning/passportjs/open-auth/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickCallback (node.js:442:13)

我正在使用ExpressJS,mongoose并注册了Linkedin应用程序以获取API密钥和密钥。我已经检查了OAuth 2.0重定向网址。

用户架构:

//Create a user model
var User = mongoose.model('User',{
    oauthID:Number,
    name:String,
    created:Date
});

这就是我配置linkedStrategy的方式:

passport.use(new LinkedInStrategy({
    clientID:config.linkedin_oauth2.clientID,
    clientSecret:config.linkedin_oauth2.clientSecret,
    callbackURL:'http://localhost:3000/auth/linkedin/callback',
    state:true,
    scope: ['r_basicprofile']
},

有什么建议吗?非常感谢你!

1 个答案:

答案 0 :(得分:0)

不确定您是否找到了答案。我遇到了同样的问题,事实证明从节点0.10.35升级到0.12.2为我修复了它。