identity-toolkit-node-clientNode.js 上的 Google Identity Toolkit 客户端
identity-toolkit-node-client 是 Node.js 上的 Google Identity Toolkit 客户端的开发包。可用于初始化 Gitkit 客户端;验证 Gitkit 令牌字符串;上传多个帐户;下载和删除账户;获得 URL 来确定用户的 email 。
代码示例:
初始化 Gitkit 客户端:
var GitkitClient = require('gitkitclient'); var gitkitClient = new GitkitClient({ 'clientId' : GOOGLE_OAUTH2_WEB_CLIENT_ID, 'serviceAccountEmail' : SERVICE_ACCOUNT_EMAIL@developer.gserviceaccount.com, 'serviceAccountPrivateKeyFile' : PRIVATE_KEY_IN_PEM_FORMAT.pem, 'widgetUrl' : 'http://localhost:8000/gitkit', 'cookieName' : 'gtoken' });
上传多个账户:
var hashKey = new Buffer('key123'); var hashOptions = { 'hashAlgorithm': 'HMAC_SHA1', 'hashKey': hashKey }; function createNewUsers(hashKey) { var crypto = require('crypto'); var user1 = { localId: '1234', email: '1234@example.com', 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); } });
评论