Permalink
Browse files

Refactor cookie helper back to its original signature to avoid API br…

…eakage (and hide the cookie implementation details - nobody needs to see that ;)).
  • Loading branch information...
1 parent 292980f commit 171791705f5079c58a8e62d3fee6112f5276163e @oesmith oesmith committed May 7, 2011
Showing with 15 additions and 10 deletions.
  1. +15 −10 lib/twitter.js
View
@@ -256,14 +256,10 @@ Twitter.prototype.stream = function(method, params, callback) {
* TWITTER "O"AUTHENTICATION UTILITIES, INCLUDING THE GREAT
* CONNECT/STACK STYLE TWITTER "O"AUTHENTICATION MIDDLEWARE
*/
-Twitter.prototype.cookie = function(cookies) {
+Twitter.prototype.cookie = function(req) {
// Fetch the cookie
- try {
- var twauth = JSON.parse(cookies.get(this.options.cookie));
- } catch (error) {
- var twauth = null;
- }
- return twauth;
+ var cookies = new Cookies(req, null, this.keygrip);
+ return this._readCookie(cookies);
}
Twitter.prototype.login = function(mount, success) {
@@ -294,7 +290,7 @@ Twitter.prototype.login = function(mount, success) {
// Fetch the cookie
var cookies = new Cookies(req, res, self.keygrip);
- var twauth = self.cookie(cookies);
+ var twauth = self._readCookie(cookies);
// We have a winner, but they're in the wrong place
if ( twauth && twauth.user_id && twauth.access_token_secret ) {
@@ -366,8 +362,7 @@ Twitter.prototype.gatekeeper = function(failure) {
mount = this.options.login_mount || '/twauth';
return function(req, res, next) {
- var cookies = new Cookies(req, res, self.keygrip);
- var twauth = self.cookie(cookies);
+ var twauth = self.cookie(req);
// We have a winner
if ( twauth && twauth.user_id && twauth.access_token_secret )
@@ -987,3 +982,13 @@ Twitter.prototype._getUsingCursor = function(url, params, callback) {
return this;
}
+
+Twitter.prototype._readCookie = function(cookies) {
+ // parse the auth cookie
+ try {
+ var twauth = JSON.parse(cookies.get(this.options.cookie));
+ } catch (error) {
+ var twauth = null;
+ }
+ return twauth;
+}

0 comments on commit 1717917

Please sign in to comment.