Skip to content
This repository has been archived by the owner on Dec 29, 2018. It is now read-only.

Commit

Permalink
fix 500 for GET requests to kongregate auth. swarmsim/swarm#630
Browse files Browse the repository at this point in the history
  • Loading branch information
erosson committed May 2, 2015
1 parent 966fbb0 commit d9fbdab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/passport-kongregate/strategy.coffee
Expand Up @@ -28,11 +28,13 @@ module.exports = class Strategy extends passport.Strategy
super()

authenticate: (req, options={}) ->
params = req.body
if !params?
return @fail {}, 404
req.checkBody('user_id').notEmpty().isInt()
req.checkBody('game_auth_token').notEmpty()
params = req.body
if (errors=req.validationErrors())
@fail {errors:errors}, 400
return @fail {errors:errors}, 400
creds = {user_id:params.user_id, game_auth_token:params.game_auth_token}
kong_args = _.extend {api_key:@options.apiKey}, creds
sails.log.debug 'kongregate auth', kong_args
Expand Down
15 changes: 15 additions & 0 deletions test/lib/passport-kongregate/strategy.test.coffee
Expand Up @@ -51,3 +51,18 @@ describe 'kongregate passport', ->
user_id: 111
game_auth_token: 'token'
@strategy.authenticate req

it 'fails for GET requests', (done) =>
@user = {}
@https =
get: sinon.spy (url, cb) =>
assert false
@protocol = sinon.spy (req, creds, profile, cb) =>
assert false
@strategy = new Strategy {apiKey: 'thekey', https: @https}, @protocol
@strategy.success = @strategy.error = sinon.stub().throws()
@strategy.fail = =>
done()
stubreq (req) =>
delete req.body
@strategy.authenticate req

0 comments on commit d9fbdab

Please sign in to comment.