Skip to content

Commit

Permalink
Merge pull request #7 from civicteam/hotfix/fix-lost-error
Browse files Browse the repository at this point in the history
Hotfix: fix lost error
  • Loading branch information
stewart42 authored Oct 16, 2017
2 parents 29d4797 + 0b4e456 commit 4d97232
Show file tree
Hide file tree
Showing 5 changed files with 3,456 additions and 2,043 deletions.
32 changes: 23 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var stringify = require('json-stringify');
var util = require('util');
var uritemplate = require('./lib/url-template/url-template');
var apiGateway = require('./lib/apiGatewayCore/apiGatewayClient');
var basicCrypto = require('./lib/basicCrypto');
Expand All @@ -34,8 +35,8 @@ sipClientFactory.newClient = function (config) {
*/

var exchangeCode = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(jwtToken) {
var body, authHeader, contentLength, additionalParams, params, scopeRequestAuthCodePostRequest, data, errorObj, response;
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(jwtToken) {
var body, authHeader, contentLength, additionalParams, params, scopeRequestAuthCodePostRequest, data, errorObj, response, errorStr;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
Expand Down Expand Up @@ -74,33 +75,46 @@ sipClientFactory.newClient = function (config) {
break;
}

errorObj = new Error('Error exchanging code for data: ', response.status);
errorObj = new Error('Error exchanging code for data: ' + response.status);
_context.next = 16;
break;

case 15:
return _context.abrupt('return', verifyAndDecrypt(response.data));

case 16:
_context.next = 21;
_context.next = 23;
break;

case 18:
_context.prev = 18;
_context.t0 = _context['catch'](7);

// console.log('Civic ERROR response: ', JSON.stringify(error, null, 2));
errorObj = new Error('Error exchanging code for data: ' + _context.t0.data && _context.t0.data.message);
// console.log('Civic ERROR response: ', util.inspect(error));

case 21:
errorStr = void 0;

if (typeof _context.t0 === 'string') {
errorStr = _context.t0;
} else if (_context.t0.data && _context.t0.data.message) {
errorStr = _context.t0.data.message;
} else if (_context.t0.data) {
errorStr = _context.t0.data;
} else {
errorStr = util.inspect(_context.t0);
}

errorObj = new Error('Error exchanging code for data: ' + errorStr);

case 23:
if (!errorObj) {
_context.next = 23;
_context.next = 25;
break;
}

throw errorObj;

case 23:
case 25:
case 'end':
return _context.stop();
}
Expand Down
8 changes: 4 additions & 4 deletions dist/test/civic.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ describe('jsRsaSign JWTToken module', function () {
// read in prv key and sign token
var prv_JWK = rsu.readFile("test/keys/prvJWK_Key_verify_test.bin");
var prvKey = JSON.parse(prv_JWK);
var token = generateToken(prvKey
var token = generateToken(prvKey);

// read in public key in JWK format and verify token
);var pub_JWK = rsu.readFile("test/keys/pubJWK_Key_verify_test.bin");
var pub_JWK = rsu.readFile("test/keys/pubJWK_Key_verify_test.bin");
var pub_json = JSON.parse(pub_JWK);
var pubKey = rs.KEYUTIL.getKey(pub_json);
// verify JWT
Expand Down Expand Up @@ -248,10 +248,10 @@ describe('jsRsaSign JWTToken module', function () {
var allowedMethod = tokenDetails.data.method;
var allowedPath = tokenDetails.data.path;
assert(allowedMethod === 'POST', 'POST must be specified.');
assert(allowedPath === 'scopeRequest/authCode', 'incorrect path.'
assert(allowedPath === 'scopeRequest/authCode', 'incorrect path.');

// partner public key
);var pubKey = new rs.KJUR.crypto.ECDSA({ curve: curve });
var pubKey = new rs.KJUR.crypto.ECDSA({ curve: curve });
pubKey.setPublicKeyHex(partner_pub_key);
pubKey.isPrivate = false;
pubKey.isPublic = true;
Expand Down
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const stringify = require('json-stringify');
const util = require('util');
const uritemplate = require('./lib/url-template/url-template');
const apiGateway = require('./lib/apiGatewayCore/apiGatewayClient');
const basicCrypto = require('./lib/basicCrypto');
Expand Down Expand Up @@ -192,18 +193,29 @@ sipClientFactory.newClient = function (config) {
let data, errorObj;

try {

const response = await apiGatewayClient.makeRequest(scopeRequestAuthCodePostRequest, authType, additionalParams);
// console.log('Civic response: ', JSON.stringify(response, null, 2));
if (response.status != 200) {
errorObj = new Error('Error exchanging code for data: ' , response.status);
errorObj = new Error('Error exchanging code for data: ' + response.status);
} else {
return verifyAndDecrypt(response.data);
}

} catch(error) {
// console.log('Civic ERROR response: ', JSON.stringify(error, null, 2));
errorObj = new Error('Error exchanging code for data: ' + error.data && error.data.message);
// console.log('Civic ERROR response: ', util.inspect(error));

let errorStr;
if (typeof error === 'string') {
errorStr = error;
} else if (error.data && error.data.message) {
errorStr = error.data.message;
} else if (error.data) {
errorStr = error.data;
} else {
errorStr = util.inspect(error);
}

errorObj = new Error('Error exchanging code for data: ' + errorStr);
}

if (errorObj) {
Expand Down
Loading

0 comments on commit 4d97232

Please sign in to comment.