Skip to content

Commit

Permalink
Doing JWT decoding by hand instead of using jwt_decode, workaround fo…
Browse files Browse the repository at this point in the history
…r minification issues in hs-ui
  • Loading branch information
DavidMikeSimon committed Feb 17, 2017
1 parent f3df1a9 commit 0732fc7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"sub": true,
"globals": {
"angular": false,
"jwt_decode": false
"base64": false
}
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"angular": "1.5.*",
"angular-resource": "1.5.*",
"jwt-decode": "2.1.0"
"base-64": "0.1.*"
},
"devDependencies": {
"angular-mocks": "1.5.*",
Expand Down
13 changes: 9 additions & 4 deletions build/secure-ng-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* secure-ng-resource JavaScript Library
* https://github.com/AmericanCouncils/secure-ng-resource/
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 02/16/2017 11:01
* Compiled At: 02/17/2017 09:34
***********************************************/
(function(window) {
'use strict';
Expand Down Expand Up @@ -418,15 +418,20 @@ function($http, $q) {
httpConf.headers.Authorization = 'Bearer ' + state.jwt;
},

_newStateFromJWT: function (jwt_raw) {
var jwt = jwt_decode(jwt_raw);
_newStateFromJWT: function (jwtRaw) {
var jwt = this._jwtDecode(jwtRaw);
var newState = {
jwt: jwt_raw,
jwt: jwtRaw,
userId: jwt.sub
};
if (this.refreshUrl) {
newState['millisecondsToRefresh'] = 1000*60*15;}
return newState;
},

_jwtDecode: function(jwtRaw) {
var b64 = jwtRaw.split('.')[1].replace('-', '+').replace('_','/');
return JSON.parse(base64.decode(b64));
}
};

Expand Down
2 changes: 1 addition & 1 deletion build/secure-ng-resource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/services/PasswordJWTAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,21 @@ function($http, $q) {
httpConf.headers.Authorization = 'Bearer ' + state.jwt;
},

_newStateFromJWT: function (jwt_raw) {
var jwt = jwt_decode(jwt_raw);
_newStateFromJWT: function (jwtRaw) {
var jwt = this._jwtDecode(jwtRaw);
var newState = {
jwt: jwt_raw,
jwt: jwtRaw,
userId: jwt.sub
};
if (this.refreshUrl) {
newState['millisecondsToRefresh'] = 1000*60*15; // 15 minutes
}
return newState;
},

_jwtDecode: function(jwtRaw) {
var b64 = jwtRaw.split('.')[1].replace('-', '+').replace('_','/');
return JSON.parse(base64.decode(b64));
}
};

Expand Down
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function(config) {
'bower_components/angular/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/base-64/base64.js',
'build/secure-ng-resource.debug.js',
'test/unit/*Spec.js'
],
Expand Down

0 comments on commit 0732fc7

Please sign in to comment.