identity-toolkit-node-clientNode.js 上的?Google Identity Toolkit 客戶端
identity-toolkit-node-client 是 Node.js 上的 Google Identity Toolkit 客戶端的開發(fā)包。可用于初始化 Gitkit 客戶端;驗(yàn)證 Gitkit 令牌字符串;上傳多個(gè)帳戶;下載和刪除賬戶;獲得 URL 來確定用戶的 email 。
代碼示例:
初始化 Gitkit 客戶端:
var GitkitClient = require('gitkitclient');
var gitkitClient = new GitkitClient({
'clientId' : GOOGLE_OAUTH2_WEB_CLIENT_ID,
'serviceAccountEmail' : [email protected],
'serviceAccountPrivateKeyFile' : PRIVATE_KEY_IN_PEM_FORMAT.pem,
'widgetUrl' : 'http://localhost:8000/gitkit',
'cookieName' : 'gtoken'
});
上傳多個(gè)賬戶:
var hashKey = new Buffer('key123');
var hashOptions = {
'hashAlgorithm': 'HMAC_SHA1',
'hashKey': hashKey
};
function createNewUsers(hashKey) {
var crypto = require('crypto');
var user1 = {
localId: '1234',
email: '[email protected]',
salt: new Buffer('salt-1'),
passwordHash: crypto.createHmac('SHA1', hashKey).update('1111' + 'salt-1').digest()
};
return [user1];
}
gitkitClient.uploadAccount(createNewUsers(hashKey), hashOptions, function (err, resp){
if (err) {
console.log('error: ', err);
} else {
console.log(resp);
}
});
評(píng)論
圖片
表情
