Skip to content

Commit

Permalink
Add google oauth 1.0 module
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoguchi committed Apr 26, 2012
1 parent eb394f1 commit ae47e87
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/modules/google1.js
@@ -0,0 +1,60 @@
var oauthModule = require('./oauth')
, extractHostname = require('../utils').extractHostname;

var google = module.exports =
oauthModule.submodule('google1')
.configurable({
scope: "URL identifying the Google service to be accessed. See the documentation for the API you'd like to use for what scope to specify. To specify more than one scope, list each one separated with a space."
})
.apiHost('https://www.google.com')
.oauthHost('https://www.google.com')

.entryPath('/auth/google1')
.callbackPath('/auth/google1/callback')

.requestTokenPath('/accounts/OAuthGetRequestToken')
.authorizePath('/accounts/OAuthAuthorizeToken')
.accessTokenPath('/accounts/OAuthGetAccessToken')

.requestTokenQueryParam({
access_type: 'offline'
, approval_prompt: 'force'
, scope: function () {
return this._scope && this.scope();
}
})

.fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
var promise = this.Promise()
, userUrl = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json';
this.oauth.get(userUrl, accessToken, accessTokenSecret, function (err, data, res) {
if (err) {
err.extra = {data: data, res: res};
return promise.fail(err);
}
var oauthUser = JSON.parse(data)
, user = { gmail: oauthUser.feed.id.$t };
promise.fulfill(user);
});
return promise;
})
.moduleErrback( function (err, seqValues) {
if (err instanceof Error) {
var next = seqValues.next;
return next(err);
} else if (err.extra) {
var twitterResponse = err.extra.res
, serverResponse = seqValues.res;
serverResponse.writeHead(
twitterResponse.statusCode
, twitterResponse.headers);
serverResponse.end(err.extra.data);
} else if (err.statusCode) {
var serverResponse = seqValues.res;
serverResponse.writeHead(err.statusCode);
serverResponse.end(err.data);
} else {
console.error(err);
throw new Error('Unsupported error type');
}
});

0 comments on commit ae47e87

Please sign in to comment.