Skip to content

Commit

Permalink
Merge pull request #2 from auth0/bugfix-base64-decode-special-char
Browse files Browse the repository at this point in the history
base64 decode issue
  • Loading branch information
hzalaz committed Oct 17, 2014
2 parents 8b25554 + 46af894 commit 664bb8f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
15 changes: 6 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
reference: http://www.objc.io/issue-6/travis-ci.html

language: objective-c

cache:
- bundler
- cocoapods

- bundler
- cocoapods
podfile: Example/Podfile

before_install:
- gem install cocoapods --no-ri --no-rdoc
- gem install xcpretty --no-ri --no-rdoc

script:
- xcodebuild -workspace Example/JWTDecode.xcworkspace -scheme JWTDecode -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO test | xcpretty -c ; exit ${PIPESTATUS[0]}

branches:
only:
- master
- master
notifications:
slack:
secure: UIG9+o5gRYZGpRRBIB/9nFBoXvSOI3Ll63KuUMd/u/CvFpByLY0MSX5LY18v6hYqA3UNjEhOO9x1j91H7JOjbI0NYtq/7+qehUDWORaQc+NSUozKLmkIGm1M6RYayUw61J9fYpyt8AjpbGIb78i7T8ckz7dYkyhEJcGz7L+30pw=
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Expecta (0.3.1)
- JWTDecode (0.2.0)
- JWTDecode (0.2.1)
- Specta (0.2.1)

DEPENDENCIES:
Expand All @@ -14,7 +14,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Expecta: 03aabd0a89d8dea843baecb19a7fd7466a69a31d
JWTDecode: fd4bdd2324eef8cf2203c1ea1e51bf46972169e4
JWTDecode: e94cb969a7f8e69533b0f76ff65d90238d90cb7d
Specta: 9141310f46b1f68b676650ff2854e1ed0b74163a

COCOAPODS: 0.34.1
22 changes: 19 additions & 3 deletions Example/Tests/A0JWTDecoderSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "Specta.h"
#import "A0JWTDecoder.h"

#define kJWTWithSpecialChars @"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1M2VjNjdkODI1NDIyMzE3MDAzNGYxNzciLCJlbWFpbCI6Im15ZW1haWxAZ21haWwuY29tIiwicHJvZmlsZV9waWN0dXJlIjoiaHR0cDovL2Nkbi51YnVidWJ0ZXN0ZXIuaW8vN2Q4MjU0MjIzMTcwMDM0ZjE3Ny5wbmc_dD0xNDEzNDQyMTI4OTAwIiwiaWF0IjoxNDEzNDcyNzUyfQ.WEELiFZqavfxPcnZ7vz44gbPMbEc0xeCaaS53btTYXY"

NSString *A0TokenJWTCreate(NSDate *expireDate) {
NSString *claims = [NSString stringWithFormat:@"{\"exp\": %f}", expireDate.timeIntervalSince1970];
Expand Down Expand Up @@ -136,6 +137,21 @@
});
});

context(@"valid id_token with special chars", ^{

beforeEach(^{
payload = [A0JWTDecoder payloadOfJWT:kJWTWithSpecialChars error:&error];
});

specify(@"payload", ^{
expect(payload).notTo.beEmpty();
});

specify(@"no error", ^{
expect(error).to.beNil();
});
});

sharedExamplesFor(@"invalid id_token", ^(NSDictionary *data) {

beforeEach(^{
Expand All @@ -150,13 +166,13 @@
specify(@"an error", ^{
expect(error).toNot.beNil();
});

});

itShouldBehaveLike(@"invalid id_token", @{ @"id_token": @"NOPARTS" });
itShouldBehaveLike(@"invalid id_token", @{ @"id_token": @"NOTENOUGH.PARTS" });
itShouldBehaveLike(@"invalid id_token", @{ @"id_token": @"HEADER.INVALIDCLAIM.SIGNATURE" });
});
});

SpecEnd
SpecEnd
2 changes: 1 addition & 1 deletion JWTDecode.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JWTDecode"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "A JSON Web Token decoder for iOS"
s.description = <<-DESC
A Simple JSON Web Token decoder for iOS that also helps you checking it's expiration date.
Expand Down
3 changes: 3 additions & 0 deletions Pod/Classes/A0JWTDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ + (NSDictionary *)payloadOfJWT:(NSString *)jwt error:(NSError *__autoreleasing *
NSInteger requiredLength = (4 * ceil((double)claimsLength / 4.0));
NSInteger paddingCount = requiredLength - claimsLength;

claimsBase64 = [claimsBase64 stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
claimsBase64 = [claimsBase64 stringByReplacingOccurrencesOfString:@"_" withString:@"/"];

if (paddingCount > 0) {
NSString *padding =
[[NSString string] stringByPaddingToLength:paddingCount
Expand Down

0 comments on commit 664bb8f

Please sign in to comment.