Javascript Linkedin与Meteor的集成
我正在开发Meteor,试图实现linkedin oauth。我有一个按钮,当用户单击它时,会出现一个窗口,要求用户允许访问,当用户允许时,必须显示用户的配置文件信息 我的方法 当按钮被点击时,我正在注射这个Javascript Linkedin与Meteor的集成,javascript,meteor,oauth-2.0,linkedin,linkedin-api,Javascript,Meteor,Oauth 2.0,Linkedin,Linkedin Api,我正在开发Meteor,试图实现linkedin oauth。我有一个按钮,当用户单击它时,会出现一个窗口,要求用户允许访问,当用户允许时,必须显示用户的配置文件信息 我的方法 当按钮被点击时,我正在注射这个 "window.open('https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=XXXXXXX&redirect_uri=http%3A%2F%2Flocalhost%
"window.open('https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=XXXXXXX&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2F_oauth%2Flinkedin%3Fclose&scope=&state=XXXXX', 'newwindow', 'width=400, height=250');"
这将打开一个请求访问权限的新窗口。当用户通过提供用户名和密码允许访问时,窗口会立即关闭。我知道linkedin将其定向到我们的应用程序,并在url中给出授权代码和状态。我需要使用这个授权码来获取访问令牌。但是我没法捕捉到这个授权码
请告诉我如何实现此功能,以及我的方法是否正确 使用帐户linkedin软件包执行以下操作: 您可以添加以下内容:
流星添加帐户linkedin
或者,如果你真的想知道它是如何完成的,请查看该软件包的源代码。这是对所有投票否决该问题的人的回答。我终于做到了
Session.set('authCode',null);
Session.set('profile',null);
Template.home.events({
'click .viewLinkedinProfileButton' :function(event, template){
var redirect_uri = encodeURIComponent(Meteor.absoluteUrl('userAuthComplete'));
var client_id='XXXXXXX';
var state = 'myRandomString';
var scope = ['r_basicprofile'];
var url = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id="+client_id+"&redirect_uri="+redirect_uri+"&state="+state+"&scope=r_basicprofile";
showPopup(url,function(err){
if(err){
console.log("Cancelled "+err);
}
else{
Meteor.call('getAccessToken',Session.get('authCode'),function(err,res){
if(res){
console.log(res);
Session.set('profile',res);
}
});
Session.set('authCode',null);
}
})
}
});
function showPopup(url, callback, dimensions) {
// default dimensions that worked well for facebook and google
var popup = openCenteredPopup(
url,
(dimensions && dimensions.width) || 650,
(dimensions && dimensions.height) || 331
);
var checkPopupOpen = setInterval(function() {
try {
var popupClosed = popup.closed || popup.closed === undefined;
} catch (e) {
return;
}
if (popupClosed) {
var url = popup.document.URL;
if(url.toLowerCase().indexOf('code') !== -1){
var array1 = url.split('code=');
var array2 =array1[1].split('&');
Session.set('authCode',array2[0]);
clearInterval(checkPopupOpen);
callback();
}
else{
clearInterval(checkPopupOpen);
}
}
}, 50);
}
function openCenteredPopup(url, width, height) {
var screenX = typeof window.screenX !== 'undefined'
? window.screenX : window.screenLeft;
var screenY = typeof window.screenY !== 'undefined'
? window.screenY : window.screenTop;
var outerWidth = typeof window.outerWidth !== 'undefined'
? window.outerWidth : document.body.clientWidth;
var outerHeight = typeof window.outerHeight !== 'undefined'
? window.outerHeight : (document.body.clientHeight - 22);
var left = screenX + (outerWidth - width) / 2;
var top = screenY + (outerHeight - height) / 2;
var features = ('width=' + width + ',height=' + height +
',left=' + left + ',top=' + top + ',scrollbars=yes');
var newwindow = window.open(url, 'Login', features);
if (newwindow.focus)
newwindow.focus();
return newwindow;
}
Template.home.helpers({
profile:function(){
return Session.get('profile');
}
});
谢谢你的-1。哈哈,很高兴来到这里,回答你的问题,然后投票表决。这在过去对我很有效。下载量为8.3k,所以问题可能出在你身上我没有投票否决你,你这个傻瓜。我刚刚创建了我的SO账户,只有2个声誉,所以不能否决任何问题。哈哈。我的错。两个人投票否决了你!但不是我。最诚挚的道歉别担心。。。也许他们不明白这个问题,f!柏油!