Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement support for force_login and screen_name params.

  • Loading branch information...
commit 891f3baef8c2c7987747c19657fdc5c9a99d780b 1 parent 830442a
@jaredhanson authored
Showing with 44 additions and 2 deletions.
  1. +21 −2 lib/passport-twitter/strategy.js
  2. +23 −0 test/strategy-test.js
View
23 lib/passport-twitter/strategy.js
@@ -65,7 +65,7 @@ util.inherits(Strategy, OAuthStrategy);
* @param {Object} req
* @api protected
*/
-Strategy.prototype.authenticate = function(req) {
+Strategy.prototype.authenticate = function(req, options) {
// When a user denies authorization on Twitter, they are presented with a link
// to return to the application in the following format (where xxx is the
// value of the request token):
@@ -79,7 +79,7 @@ Strategy.prototype.authenticate = function(req) {
}
// Call the base class for standard OAuth authentication.
- OAuthStrategy.prototype.authenticate.call(this, req);
+ OAuthStrategy.prototype.authenticate.call(this, req, options);
}
/**
@@ -132,6 +132,25 @@ Strategy.prototype.userProfile = function(token, tokenSecret, params, done) {
}
}
+/**
+ * Return extra Twitter-specific parameters to be included in the user
+ * authorization request.
+ *
+ * @param {Object} options
+ * @return {Object}
+ * @api protected
+ */
+Strategy.prototype.userAuthorizationParams = function(options) {
+ var params = {};
+ if (options.forceLogin) {
+ params['force_login'] = options.forceLogin;
+ }
+ if (options.screenName) {
+ params['screen_name'] = options.screenName;
+ }
+ return params;
+}
+
/**
* Expose `Strategy`.
View
23 test/strategy-test.js
@@ -20,6 +20,29 @@ vows.describe('TwitterStrategy').addBatch({
},
},
+ 'strategy user authorization params': {
+ topic: function() {
+ return new TwitterStrategy({
+ consumerKey: 'ABC123',
+ consumerSecret: 'secret'
+ },
+ function() {});
+ },
+
+ 'should return empty object when parsing invalid options': function (strategy) {
+ var params = strategy.userAuthorizationParams({ foo: 'bar' });
+ assert.lengthOf(Object.keys(params), 0);
+ },
+ 'should return force_login': function (strategy) {
+ var params = strategy.userAuthorizationParams({ forceLogin: true });
+ assert.equal(params.force_login, true);
+ },
+ 'should return screen_name': function (strategy) {
+ var params = strategy.userAuthorizationParams({ screenName: 'bob' });
+ assert.equal(params.screen_name, 'bob');
+ },
+ },
+
'strategy when loading user profile': {
topic: function() {
var strategy = new TwitterStrategy({
Please sign in to comment.
Something went wrong with that request. Please try again.