【发布时间】:2015-02-16 12:55:28
【问题描述】:
我已经完成了 linkedin OAuth2 身份验证的第 1 步和第 2 步(在此处详细介绍 https://developer.linkedin.com/docs/oauth2),但我无法在第 3 步中检索访问令牌。我正在使用带有 express.js 的 node.js 服务器向 https://www.linkedin.com/uas/oauth2/accessToken 端点发出 https 发布请求,其中包含文档中列出的所有参数。我的请求代码是:
// Request paramaters
var post_data = querystring.stringify({
'grant_type' : 'authorization_code',
'code': auth_code,
'redirect_uri': 'http://localhost:4200/authenticated',
'client_id': '**************',
'client_secret': '****************'
});
// Request options object
var post_options = {
host: 'www.linkedin.com',
port: '443',
path: '/uas/oauth2/accessToken',
method: 'POST'
};
// Setup the request
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// Post the data
post_req.write(post_data);
post_req.end();
但是,在发出请求时,服务器会从linkedin记录以下错误响应:
Response: {"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}
【问题讨论】:
-
很高兴您尝试自己实现社交身份验证,大多数人更喜欢使用passport,它是Node.js 的身份验证中间件。试试看,你可以节省很多时间。
-
@NarendraSoni 我使用 ember.js 作为客户端和 firebase 来存储我的所有模型——我只需要这个节点服务器与linkedin api 进行通信以进行身份验证并首先提取用户的完整配置文件他们进行身份验证的时间。我可以在其文档的第 1 步中使用来自linkedin auth 重定向的用户授权代码初始化护照和passport-linkedin 包吗?
-
我更喜欢 AngularJS,没有改变来研究 EmberJS,但我相信这个概念一定非常相似。找到我的
github回购 mean-passport-auth 我这两天开发的基于角色的本地和 Facebook 身份验证。我认为您可以在 EmberJS 中获得一个想法并实现相同的东西。添加到它。我将在一周左右的时间里改进这个应用程序以提供基于 ** javascript web token(JWT) ** 的身份验证。那将是最好的。所以尝试达到同样的效果。一切顺利。 -
太棒了,我会研究一下。