UNPKG

r-oauth2

Version:

A RethinkDB and Express implementation of OAuth2

48 lines (44 loc) 1.14 kB
var async = require('async'); var request = require('request'); var client, oauth, host = "http://localhost:9001"; describe('This validates that the demo runs correctly.', function() { it('Create a client and token', function(done) { async.series([ function(callback) { request.post({ url: host + "/client", form: { grantType: "user" } }, function(err, res, body) { body = JSON.parse(body); client = body; callback(null); }) }, function(callback) { request.post({ url: host + "/oauth", form: { client: client } }, function(err, res, body) { body = JSON.parse(body); oauth = body; done(); }) } ]) }) it('Access restricted area', function(done) { request.get({ url: host + "/restricted", headers: { "Authorization": "Bearer " + oauth.accessToken } }, function(err, res, body) { if (res.statusCode != 200) throw "Invalid status code."; done(); }) }) })