Skip to content

Commit

Permalink
Merge pull request #11 from jhkuperus/patch-1
Browse files Browse the repository at this point in the history
Added support for multiple URL-safe chars in base64 tokens
  • Loading branch information
mgonto committed Nov 22, 2014
2 parents e18814b + 4c2fcb4 commit 91d16ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/angularJwt/services/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.service('jwtHelper', function() {

this.urlBase64Decode = function(str) {
var output = str.replace('-', '+').replace('_', '/');
var output = str.replace(/-/g, '+').replace(/_/g, '/');
switch (output.length % 4) {
case 0: { break; }
case 2: { output += '=='; break; }
Expand Down
7 changes: 7 additions & 0 deletions test/unit/angularJwt/services/jwtSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ describe('jwt', function() {
expect(token.name).to.equal('John Doe');
}));

var multipleUrlCharactersToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEyMzQ1Njc4OTAsIm5hbWUiOiJKb2huIERvZWxsbO-jv2xsbO-jvyIsImFkbWluIjp0cnVlfQ.NCPM3vNwuvJGMIjR0csEFQDrSLcjm5P7ORumVq4ezmo';
it('should correctly decode tokens with multiple URL-safe characters', inject(function (jwtHelper) {
var token = jwtHelper.decodeToken(multipleUrlCharactersToken);

expect(token.name).to.equal('John Doellllll');
}));

it('should return no expiration', inject(function (jwtHelper) {
var date = jwtHelper.getTokenExpirationDate(infiniteToken);

Expand Down

0 comments on commit 91d16ae

Please sign in to comment.