forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e42e98
commit a80d40b
Showing
4 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* `FacebookTokenError` error. | ||
* | ||
* FacebookTokenError represents an error received from a Facebook's token | ||
* endpoint. Note that these responses don't conform to the OAuth 2.0 | ||
* specification. | ||
* | ||
* References: | ||
* - https://developers.facebook.com/docs/reference/api/errors/ | ||
* | ||
* @constructor | ||
* @param {String} [message] | ||
* @param {String} [type] | ||
* @param {Number} [code] | ||
* @param {Number} [subcode] | ||
* @api public | ||
*/ | ||
function FacebookTokenError(message, type, code, subcode) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.name = 'FacebookTokenError'; | ||
this.message = message; | ||
this.type = type; | ||
this.code = code; | ||
this.subcode = subcode; | ||
this.status = 500; | ||
} | ||
|
||
/** | ||
* Inherit from `Error`. | ||
*/ | ||
FacebookTokenError.prototype.__proto__ = Error.prototype; | ||
|
||
|
||
/** | ||
* Expose `FacebookTokenError`. | ||
*/ | ||
module.exports = FacebookTokenError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
var chai = require('chai') | ||
, FacebookStrategy = require('../lib/strategy'); | ||
|
||
|
||
describe('Strategy', function() { | ||
|
||
describe('using token endpoint that responds with non-standard error', function() { | ||
var strategy = new FacebookStrategy({ | ||
clientID: 'ABC123', | ||
clientSecret: 'secret' | ||
}, | ||
function() {}); | ||
|
||
// inject a "mock" oauth2 instance | ||
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) { | ||
return callback({ statusCode: 400, data: '{"error":{"message":"Invalid verification code format.","type":"OAuthException","code":100}}' }); | ||
} | ||
|
||
describe('handling response', function() { | ||
var err; | ||
|
||
before(function(done) { | ||
chai.passport(strategy) | ||
.error(function(e) { | ||
err = e; | ||
done(); | ||
}) | ||
.req(function(req) { | ||
req.query = {}; | ||
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA+ALT1'; | ||
}) | ||
.authenticate(); | ||
}); | ||
|
||
it('should error', function() { | ||
expect(err.constructor.name).to.equal('FacebookTokenError'); | ||
expect(err.message).to.equal('Invalid verification code format.'); | ||
expect(err.type).to.equal('OAuthException'); | ||
expect(err.code).to.equal(100); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('using token endpoint that responds with standard error', function() { | ||
var strategy = new FacebookStrategy({ | ||
clientID: 'ABC123', | ||
clientSecret: 'secret' | ||
}, | ||
function() {}); | ||
|
||
// inject a "mock" oauth2 instance | ||
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) { | ||
return callback({ statusCode: 400, data: '{"error":"invalid_grant","error_description":"The provided value for the input parameter \'code\' is not valid."} '}); | ||
} | ||
|
||
describe('handling response', function() { | ||
var err; | ||
|
||
before(function(done) { | ||
chai.passport(strategy) | ||
.error(function(e) { | ||
err = e; | ||
done(); | ||
}) | ||
.req(function(req) { | ||
req.query = {}; | ||
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA+ALT1'; | ||
}) | ||
.authenticate(); | ||
}); | ||
|
||
it('should error', function() { | ||
expect(err.constructor.name).to.equal('TokenError'); | ||
expect(err.message).to.equal('The provided value for the input parameter \'code\' is not valid.'); | ||
expect(err.code).to.equal('invalid_grant'); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |