Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #15 from kruppel/display_mode

Add support for dialog display param
  • Loading branch information...
commit 179a2aad07c621f27a49167da89ae3aaacc7f09d 2 parents 84e0e24 + f2d2f2e
@jaredhanson authored
View
13 README.md
@@ -56,6 +56,19 @@ application:
res.redirect('/');
});
+##### Display Mode
+
+Set `display` in `passport.authenticate()` options to specify display
+mode. Refer to the [OAuth dialog
+documentation](https://developers.facebook.com/docs/reference/dialogs/oauth/)
+for information on its usage.
+
+ app.get('/auth/facebook',
+ passport.authenticate('facebook', { display: 'mobile' }),
+ function(req, res){
+ // ...
+ });
+
#### Extended Permissions
If you need extended permissions from the user, the permissions can be requested
View
20 lib/passport-facebook/strategy.js
@@ -55,6 +55,26 @@ function Strategy(options, verify) {
*/
util.inherits(Strategy, OAuth2Strategy);
+/**
+ * Return extra parameters to be included in the authorization request.
+ *
+ * Options:
+ * - `display` Display mode to render dialog, { `page`, `popup`, `touch` }.
+ *
+ * @param {Object} options
+ * @return {Object}
+ * @api protected
+ */
+Strategy.prototype.authorizationParams = function (options) {
+ var params = {},
+ display = options.display;
+
+ if (display) {
+ params['display'] = display;
+ }
+
+ return params;
+};
/**
* Retrieve user profile from Facebook.
View
59 test/strategy-test.js
@@ -1,6 +1,7 @@
var vows = require('vows');
var assert = require('assert');
var util = require('util');
+var urlLib = require('url');
var FacebookStrategy = require('passport-facebook/strategy');
@@ -20,6 +21,64 @@ vows.describe('FacebookStrategy').addBatch({
},
},
+ 'strategy when loading authorization url': {
+ topic: function () {
+ var strategy = new FacebookStrategy({
+ clientID: 'ABC123',
+ clientSecret: 'secret'
+ });
+
+ return strategy;
+ },
+
+ 'and display not set': {
+ topic: function (strategy) {
+ var mockRequest = {},
+ url;
+
+ // Stub strategy.redirect()
+ strategy.redirect = function (location) {
+ url = location;
+
+ return location;
+ };
+ strategy.authenticate(mockRequest);
+
+ return url;
+ },
+
+ 'does not set authorization param': function(url) {
+ var params = urlLib.parse(url, true).query;
+
+ assert.isUndefined(params.display);
+ }
+ },
+
+ 'and display set to mobile': {
+ topic: function (strategy) {
+ var mockRequest = {},
+ url;
+
+ // Stub strategy.redirect()
+ strategy.redirect = function (location) {
+ url = location;
+
+ return location;
+ };
+ strategy.authenticate(mockRequest, { display: 'mobile' });
+
+ return url;
+ },
+
+
+ 'sets authorization param to mobile': function(url) {
+ var params = urlLib.parse(url, true).query;
+
+ assert.equal(params.display, 'mobile');
+ }
+ }
+ },
+
'strategy when loading user profile': {
topic: function() {
var strategy = new FacebookStrategy({
Please sign in to comment.
Something went wrong with that request. Please try again.