Skip to content

Commit

Permalink
Use namespaced OAuth parameters set on authInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jun 29, 2012
1 parent fcff12c commit af4d499
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
12 changes: 6 additions & 6 deletions lib/middleware/accessToken.js
Expand Up @@ -10,10 +10,10 @@ var utils = require('../utils')
*
* Assumptions:
*
* `req.authInfo` must be set on the request and contain `requestToken` and
* `verifier` properties. Due to the nature of OAuth, these parameters are
* transmitted along with authentication credentials and are parsed during that
* step, *prior* to this middleware being invoked.
* `req.authInfo` must be set on the request and contain `oauth.token` and
* `oauth.verifier` properties. Due to the nature of OAuth, these parameters
* are transmitted along with authentication credentials and are parsed during
* that step, *prior* to this middleware being invoked.
*
* By design, this integrates with the `ConsumerStrategy` provided by
* [passport-http-oauth](https://github.com/jaredhanson/passport-http-oauth).
Expand Down Expand Up @@ -47,8 +47,8 @@ module.exports = function accessToken(options, verify, issue) {
if (!req.authInfo) { return next(new Error('authentication info not available')); }

var consumer = req[userProp]
, requestToken = req.authInfo.requestToken
, verifier = req.authInfo.verifier;
, requestToken = req.authInfo.oauth.token
, verifier = req.authInfo.oauth.verifier;

function issued(err, token, tokenSecret, params) {
if (err) { return next(err); }
Expand Down
4 changes: 2 additions & 2 deletions lib/middleware/requestToken.js
Expand Up @@ -9,7 +9,7 @@ var utils = require('../utils')
*
* Assumptions:
*
* `req.authInfo` must be set on the request and contain a `callbackURL`
* `req.authInfo` must be set on the request and contain an `oauth.callbackURL`
* property. Due to the nature of OAuth, this parameter is transmitted along
* with authentication credentials and is parsed during that step, *prior* to
* this middleware being invoked.
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = function requestToken(options, parse, issue) {
if (!req.authInfo) { return next(new Error('authentication info not available')); }

var consumer = req[userProp]
, callbackURL = req.authInfo.callbackURL;
, callbackURL = req.authInfo.oauth.callbackURL;

function issued(err, token, tokenSecret, params) {
if (err) { return next(err); }
Expand Down
25 changes: 15 additions & 10 deletions test/middleware/accessToken-test.js
Expand Up @@ -51,8 +51,9 @@ vows.describe('accessToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.requestToken = 'hdk48Djdsa'
req.authInfo.verifier = '473f82d3'
req.authInfo.oauth = {};
req.authInfo.oauth.token = 'hdk48Djdsa'
req.authInfo.oauth.verifier = '473f82d3'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -107,8 +108,9 @@ vows.describe('accessToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.requestToken = 'hdk48Djdsa'
req.authInfo.verifier = '473f82d3'
req.authInfo.oauth = {};
req.authInfo.oauth.token = 'hdk48Djdsa'
req.authInfo.oauth.verifier = '473f82d3'
req.authInfo.user = { id: 'user-1235' }

var res = new MockResponse();
Expand Down Expand Up @@ -164,8 +166,9 @@ vows.describe('accessToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.requestToken = 'hdk48Djdsa'
req.authInfo.verifier = '473f82d3'
req.authInfo.oauth = {};
req.authInfo.oauth.token = 'hdk48Djdsa'
req.authInfo.oauth.verifier = '473f82d3'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -212,8 +215,9 @@ vows.describe('accessToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.requestToken = 'hdk48Djdsa'
req.authInfo.verifier = '473f82d3'
req.authInfo.oauth = {};
req.authInfo.oauth.token = 'hdk48Djdsa'
req.authInfo.oauth.verifier = '473f82d3'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -257,8 +261,9 @@ vows.describe('accessToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.requestToken = 'hdk48Djdsa'
req.authInfo.verifier = '473f82d3'
req.authInfo.oauth = {};
req.authInfo.oauth.token = 'hdk48Djdsa'
req.authInfo.oauth.verifier = '473f82d3'

var res = new MockResponse();
res.done = function() {
Expand Down
21 changes: 14 additions & 7 deletions test/middleware/requestToken-test.js
Expand Up @@ -42,7 +42,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback'
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -88,7 +89,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback'
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -141,7 +143,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback';
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback';
req.query = {};
req.query['scribble'] = 'scrobble';

Expand Down Expand Up @@ -189,7 +192,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.client = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback'
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -231,7 +235,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback'
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -270,7 +275,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback'
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback'

var res = new MockResponse();
res.done = function() {
Expand Down Expand Up @@ -314,7 +320,8 @@ vows.describe('requestToken').addBatch({
var req = new MockRequest();
req.user = { id: 'client-1234' };
req.authInfo = {};
req.authInfo.callbackURL = 'http://www.example.com/auth/callback';
req.authInfo.oauth = {};
req.authInfo.oauth.callbackURL = 'http://www.example.com/auth/callback';
req.query = {};
req.query['scribble'] = 'scrobble';

Expand Down

0 comments on commit af4d499

Please sign in to comment.