在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Ajnasz/GoogleClientLogin开源软件地址(OpenSource Url):https://github.com/Ajnasz/GoogleClientLogin开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Google's ClientLogin authentication implementation for Node.jsGoogle Client Login officially deprecated
Requires at least nodejs 0.4.1Properties:errors:That is an object, filled with the possible error messages. accountTypes:An object, where you can set the type of account to request authorization for. properties are: google, hosted, hostedOrGoogle default is hostedOrGoogle Events:login:emitted when login was success error:emitted when an error occured. Has two parameters, the response object and the received data You can access to their names via constants: GoogleClientLogin.events.login or GoogleClientLogin.events.error or you can use 'login' and 'error' as string. Methods:loginStarts the login process. It has one optional parameter, which should be an object with two properties: logincaptcha, logintoken. The logincaptcha is the user's answer to the captcha question You will receive the logintoken if the login failed and the CaptchaRequired error code arrived You must pass both the logincaptcha and logintoken if you must pass a captcha challange getAuthIdReturns the value of the authId key from the response. If the login was success you will need to use this value to perform additional requests. You must put it into a the Authorization header like this:
getSIDReturns the value of SID key from the response. getLSIDReturns the value of LSID key from the response. isCaptchaRequiredIf the login was not success and the user need to pass a captcha challenge this method will return true getCaptchaUrlUrl of the captcha image getCaptchaTokenYou will need to pass it back to the google with the user's answer to the captcha if the login failed and captcha authentication required. getErrorIf the login was not success, google will send back an error code what you can get with this method After the login was success, you should use the AuthId in each of your requests, see example below http://code.google.com/apis/gdata/faq.html#clientlogin list of services:
How to use:var GoogleClientLogin = import('googleclientlogin').GoogleClientLogin;
var googleAuth = new GoogleClientLogin({
email: '[email protected]',
password: 'yourpassword',
service: 'contacts',
accountType: GoogleClientLogin.accountTypes.google
});
googleAuth.on(GoogleClientLogin.events.login, function(){
// do things with google services
require('https').request({
host: 'www.google.com',
port: 443,
path: path,
method: 'GET',
headers: {
'Authorization': 'GoogleLogin auth=' + googleAuth.getAuthId(),
...
}
});
});
googleAuth.on(GoogleClientLogin.events.error, function(e) {
switch(e.message) {
case GoogleClientLogin.errors.loginFailed:
if (this.isCaptchaRequired()) {
requestCaptchaFromUser(this.getCaptchaUrl(), this.getCaptchaToken());
} else {
requestLoginDetailsAgain();
}
break;
case GoogleClientLogin.errors.tokenMissing:
case GoogleClientLogin.errors.captchaMissing:
throw new Error('You must pass the both captcha token and the captcha')
break;
}
throw new Error('Unknown error');
// damn..
});
googleAuth.login(); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论