2015-01-04 33 views
0

我正在meteor.js,並已在全球安裝NPM包node-linkedin https://www.npmjs.com/package/node-linkedin流星:當客戶端通過驗證第一次登錄LinkedIn時創建用戶帳戶?

我已經註冊了我的應用程序與LinkedIn,這意味着我有我的API密鑰,密鑰和OAuth重定向網址爲localhost:3000

我的應用程序當前顯示'登錄'linkedIn按鈕,用戶授予我的應用程序訪問用戶的完整配置文件的權限。根據linkedIn javascript API文檔,onLinkedInAuth()對象(在成功驗證時運行)包含用戶的linkedin id

如何創建一個用戶帳戶,Accounts.createUser當用戶進行身份驗證,並從用戶收集的onLinkedInAuth()對象存儲ID

server.js

var Linkedin = Npm.require('node-linkedin')('api', 'secret', 'I-PUT-REDIRECT-URL-HERE'); 

我如何使用NPM包https://www.npmjs.com/package/node-linkedin的GET請求(見標題的OAuth 2.0下),這將用戶重定向到linkedins授權對話框,然後檢索訪問令牌。

HTML:

<head> 
<script type="text/javascript" src="https://platform.linkedin.com/in.js"> 
api_key: *MY_API_KEY* 
onLoad: onLinkedInLoad 
authorize: true 
</script> 
<script type="text/javascript"> 
// Runs when the JavaScript framework is loaded 
function onLinkedInLoad() { 
IN.Event.on(IN, "auth", onLinkedInAuth); 
} 
// Runs when the viewer has authenticated 
function onLinkedInAuth() { 
IN.API.Profile("me") 
.result(function(me) { 
var id = me.values[0].id; 
// AJAX call to pass back id to your server 
}); 
} 
// Runs when the Profile() API call returns successfully 
function displayProfiles(profiles) { 
member = profiles.values[0]; 
document.getElementById("profiles").innerHTML = 
"<p id=\"" + member.id + "\">Hello " + member.firstName + " " + member.lastName + "</p>"; 
} 
</script> 
</head> 

<template name="parent"> //layout template 
<!-- Displays a button to let the viewer authenticate --> 
<script type="IN/Login" data-onAuth="onLinkedInAuth"></script> 
<!-- Placeholder for the greeting --> 
<div id="profiles"></div> 
</template> 

回答