Skip to content

Commit

Permalink
Merge pull request crashlytics#8 from twitterdev/token-verification
Browse files Browse the repository at this point in the history
Use auth-header package to verify consumer key
  • Loading branch information
Alex Singer authored Aug 17, 2016
2 parents 32fe5d5 + 43db380 commit d1983ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0",
"nconf": "^0.6.9",
"request": "^2.58.0"
"request": "^2.58.0",
"auth-header": "~0.3.1"
}
}
12 changes: 11 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var fs = require('fs');
var nconf = require('nconf');
var url = require('url');
var request = require('request');
var authorization = require('auth-header');

/**
* GET Cannonball home page.
Expand All @@ -30,8 +31,17 @@ router.post('/digits', function (req, res) {
var verified = true;
var messages = [];

// Get authorization header.
var auth = authorization.parse(credentials);

// OAuth authentication not provided.
if (auth.scheme != 'OAuth') {
verified = false;
messages.push('Invalid auth type.');
}

// Verify the OAuth consumer key.
if (credentials.indexOf('oauth_consumer_key="' + nconf.get('DIGITS_CONSUMER_KEY') + '"') == -1) {
if (auth.params.oauth_consumer_key != nconf.get('DIGITS_CONSUMER_KEY')) {
verified = false;
messages.push('The Digits API key does not match.');
}
Expand Down

0 comments on commit d1983ef

Please sign in to comment.