diff --git a/exercises/ch-11-ex-1/authorizationServer.js b/exercises/ch-11-ex-1/authorizationServer.js index be32b86b..b2c82f9b 100644 --- a/exercises/ch-11-ex-1/authorizationServer.js +++ b/exercises/ch-11-ex-1/authorizationServer.js @@ -247,28 +247,27 @@ app.post("/token", function(req, res){ return; } } else if (req.body.grant_type == 'refresh_token') { - nosql.one(function(token) { - if (token.refresh_token == req.body.refresh_token) { - return token; - } - }, function(err, token) { - if (token) { - console.log("We found a matching refresh token: %s", req.body.refresh_token); - if (token.client_id != clientId) { - nosql.remove(function(found) { return (found == token); }, function () {} ); + nosql.one().make(builder => { + builder.where('refresh_token', req.body.refresh_token); + builder.callback(function(err, token) { + if (token) { + console.log("We found a matching refresh token: %s", req.body.refresh_token); + if (token.client_id != clientId) { + nosql.remove(function(found) { return (found == token); }, function () {} ); + res.status(400).json({error: 'invalid_grant'}); + return; + } + var access_token = randomstring.generate(); + nosql.insert({ access_token: access_token, client_id: clientId }); + var token_response = { access_token: access_token, token_type: 'Bearer', refresh_token: token.refresh_token }; + res.status(200).json(token_response); + return; + } else { + console.log('No matching token was found.'); res.status(400).json({error: 'invalid_grant'}); return; } - var access_token = randomstring.generate(); - nosql.insert({ access_token: access_token, client_id: clientId }); - var token_response = { access_token: access_token, token_type: 'Bearer', refresh_token: token.refresh_token }; - res.status(200).json(token_response); - return; - } else { - console.log('No matching token was found.'); - res.status(400).json({error: 'invalid_grant'}); - return; - } + }); }); } else { console.log('Unknown grant type %s', req.body.grant_type); @@ -315,4 +314,4 @@ var server = app.listen(9001, 'localhost', function () { console.log('OAuth Authorization Server is listening at http://%s:%s', host, port); }); - + diff --git a/exercises/ch-11-ex-1/package.json b/exercises/ch-11-ex-1/package.json index 28f0e5c5..be9d909d 100644 --- a/exercises/ch-11-ex-1/package.json +++ b/exercises/ch-11-ex-1/package.json @@ -9,7 +9,7 @@ "consolidate": "^0.13.1", "qs": "^4.0.0", "randomstring": "^1.0.7", - "nosql": "^3.0.3", + "nosql": "^6.1.0", "base64url": "^1.0.4", "cors": "^2.7.1", "jsrsasign": "^5.0.0"