From 765b190f8c0a67651ea132f72f5e4dbb843daace Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Thu, 14 Sep 2017 21:08:39 +0100 Subject: [PATCH 1/6] Converted to Xcode 9 / Swift 4, Set to 3.2 Disabled CodeCov on Libs (LLVM Submission Issue Fix) Fix a broken test Updated Nimble deprecated MatcherFuncs to Predicate --- Cartfile.private | 2 +- Cartfile.resolved | 2 +- JWTDecode.xcodeproj/project.pbxproj | 50 ++++++++++++++++--- .../xcschemes/JWTDecode-OSX.xcscheme | 7 +-- .../xcschemes/JWTDecode-iOS.xcscheme | 7 +-- .../xcschemes/JWTDecode-tvOS.xcscheme | 7 +-- JWTDecodeTests/JWTDecodeSpec.swift | 13 +++-- 7 files changed, 63 insertions(+), 25 deletions(-) diff --git a/Cartfile.private b/Cartfile.private index 7954cdc..8f0c9e7 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,2 @@ github "Quick/Quick" ~> 1.1 -github "Quick/Nimble" ~> 6.0 +github "Quick/Nimble" ~> 7.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 1e28c51..4a33a6b 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "Quick/Nimble" "v6.1.0" +github "Quick/Nimble" "v7.0.1" github "Quick/Quick" "v1.1.0" diff --git a/JWTDecode.xcodeproj/project.pbxproj b/JWTDecode.xcodeproj/project.pbxproj index 86c04e3..017279a 100644 --- a/JWTDecode.xcodeproj/project.pbxproj +++ b/JWTDecode.xcodeproj/project.pbxproj @@ -470,33 +470,33 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Auth0; TargetAttributes = { 5F0068E11B3B46240048928E = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 5F0068EC1B3B46240048928E = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Manual; }; 5F0069081B3B532E0048928E = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 5F0069121B3B532E0048928E = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 918A8E5A1D63D2E1001F787B = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 918A8E6B1D63D4E5001F787B = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Manual; }; }; @@ -659,14 +659,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -710,14 +716,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -750,6 +762,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; @@ -765,6 +778,7 @@ PRODUCT_NAME = JWTDecode; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Debug; @@ -773,6 +787,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; @@ -788,6 +803,7 @@ PRODUCT_NAME = JWTDecode; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Release; @@ -796,6 +812,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_CODE_COVERAGE = YES; CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( @@ -812,6 +829,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "JWTDecodeTests/JWTDecode-iOSTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Debug; @@ -820,6 +838,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_CODE_COVERAGE = YES; CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( @@ -832,6 +851,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "JWTDecodeTests/JWTDecode-iOSTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Release; @@ -839,6 +859,7 @@ 5F00691D1B3B532E0048928E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = YES; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; @@ -859,6 +880,7 @@ PRODUCT_NAME = JWTDecode; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Debug; @@ -866,6 +888,7 @@ 5F00691E1B3B532E0048928E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = YES; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -882,6 +905,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Release; @@ -890,6 +914,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_CODE_COVERAGE = YES; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = dwarf; FRAMEWORK_SEARCH_PATHS = ( @@ -906,6 +931,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Debug; @@ -914,6 +940,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_CODE_COVERAGE = YES; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -925,6 +952,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; }; name = Release; @@ -933,6 +961,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; @@ -947,6 +976,7 @@ PRODUCT_NAME = JWTDecode; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.2; @@ -957,6 +987,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -970,6 +1001,7 @@ PRODUCT_NAME = JWTDecode; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.2; @@ -980,6 +1012,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( @@ -991,6 +1024,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.JWTDecode-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.2; }; @@ -1000,6 +1034,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_CODE_COVERAGE = YES; DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1011,6 +1046,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.2; }; diff --git a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-OSX.xcscheme b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-OSX.xcscheme index 64b569e..caab222 100644 --- a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-OSX.xcscheme +++ b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-OSX.xcscheme @@ -1,6 +1,6 @@ + language = "" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -70,6 +70,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme index 6137b16..3beb14f 100644 --- a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme +++ b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme @@ -1,6 +1,6 @@ + language = "" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -70,6 +70,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-tvOS.xcscheme b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-tvOS.xcscheme index 8a55e1e..e996b03 100644 --- a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-tvOS.xcscheme +++ b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-tvOS.xcscheme @@ -1,6 +1,6 @@ + language = "" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -70,6 +70,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/JWTDecodeTests/JWTDecodeSpec.swift b/JWTDecodeTests/JWTDecodeSpec.swift index 40e8bb1..75e299c 100644 --- a/JWTDecodeTests/JWTDecodeSpec.swift +++ b/JWTDecodeTests/JWTDecodeSpec.swift @@ -187,7 +187,7 @@ class JWTDecodeSpec: QuickSpec { let claim = token.claim(name: "custom_double_claim") expect(claim.string).to(beNil()) expect(claim.array).to(beNil()) - expect(claim.integer) == 3 + expect(claim.integer).to(beNil()) expect(claim.double) == 3.4 expect(claim.date) == Date(timeIntervalSince1970: 3.4) } @@ -214,13 +214,12 @@ class JWTDecodeSpec: QuickSpec { } } -public func beDecodeErrorWithCode(_ code: DecodeError) -> NonNilMatcherFunc { - return NonNilMatcherFunc { (actualExpression, failureMessage) throws in - failureMessage.postfixMessage = "be decode error with code <\(code)>" - guard let actual = try actualExpression.evaluate() as? DecodeError else { - return false +public func beDecodeErrorWithCode(_ code: DecodeError) -> Predicate { + return Predicate.define("be decode error with code <\(code)>") { expression, failureMessage -> PredicateResult in + guard let actual = try expression.evaluate() as? DecodeError else { + return PredicateResult(status: .doesNotMatch, message: failureMessage) } - return actual == code + return PredicateResult(bool: actual == code, message: failureMessage) } } From b983215d1486974e690d1806c1dbde0dce3c3c1a Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Fri, 22 Sep 2017 17:09:37 +0100 Subject: [PATCH 2/6] Update Circle CI to enable CodeCov Fix Test --- .../xcshareddata/xcschemes/JWTDecode-iOS.xcscheme | 3 +-- JWTDecodeTests/JWTDecodeSpec.swift | 2 +- circle.yml | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme index 3beb14f..84c14cb 100644 --- a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme +++ b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme @@ -1,7 +1,7 @@ + version = "1.8"> @@ -70,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/JWTDecodeTests/JWTDecodeSpec.swift b/JWTDecodeTests/JWTDecodeSpec.swift index 75e299c..053e380 100644 --- a/JWTDecodeTests/JWTDecodeSpec.swift +++ b/JWTDecodeTests/JWTDecodeSpec.swift @@ -187,7 +187,7 @@ class JWTDecodeSpec: QuickSpec { let claim = token.claim(name: "custom_double_claim") expect(claim.string).to(beNil()) expect(claim.array).to(beNil()) - expect(claim.integer).to(beNil()) + expect(claim.integer) == 3 expect(claim.double) == 3.4 expect(claim.date) == Date(timeIntervalSince1970: 3.4) } diff --git a/circle.yml b/circle.yml index c891534..ac1da33 100644 --- a/circle.yml +++ b/circle.yml @@ -9,6 +9,7 @@ machine: dependencies: pre: - brew install swiftlint + - grep -lR "shouldUseLaunchSchemeArgsEnv" *.* --null | xargs -0 sed -i '' -e 's/shouldUseLaunchSchemeArgsEnv = "YES"/shouldUseLaunchSchemeArgsEnv = "YES" codeCoverageEnabled = "YES"/g' post: - mkdir -p fastlane/test_output cache_directories: From 02f483c2e51d97e13748485c2eea6a39c40cae3c Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Tue, 26 Sep 2017 15:36:37 +0100 Subject: [PATCH 3/6] Modify integer claim method to be consistent in Xcode8/9 Fix Playground warning --- JWTDecode.playground/Contents.swift | 2 +- JWTDecode.playground/timeline.xctimeline | 56 +++++++++---------- JWTDecode.xcodeproj/project.pbxproj | 2 +- .../xcschemes/JWTDecode-iOS.xcscheme | 3 +- JWTDecode/JWTDecode.swift | 6 +- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/JWTDecode.playground/Contents.swift b/JWTDecode.playground/Contents.swift index 412643c..f5e54f9 100644 --- a/JWTDecode.playground/Contents.swift +++ b/JWTDecode.playground/Contents.swift @@ -48,7 +48,7 @@ do { //: ### Custom Claims //: If we also have our custom claims we can retrive them calling `claim(name: String) -> T?` where `T` is the value type of the claim, e.g.: a `String` - let custom = jwt.claim(name: "email").string + _ = jwt.claim(name: "email").string //: ### Error Handling //: If the token is invalid an `NSError` will be thrown } catch let error as NSError { diff --git a/JWTDecode.playground/timeline.xctimeline b/JWTDecode.playground/timeline.xctimeline index 59c19b4..31c735f 100644 --- a/JWTDecode.playground/timeline.xctimeline +++ b/JWTDecode.playground/timeline.xctimeline @@ -3,142 +3,142 @@ version = "3.0"> diff --git a/JWTDecode.xcodeproj/project.pbxproj b/JWTDecode.xcodeproj/project.pbxproj index 017279a..8e26df9 100644 --- a/JWTDecode.xcodeproj/project.pbxproj +++ b/JWTDecode.xcodeproj/project.pbxproj @@ -118,7 +118,7 @@ 5F0069221B3C4A7F0048928E /* JWTDecodeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JWTDecodeSpec.swift; sourceTree = ""; }; 5F00693F1B3C828E0048928E /* JWTDecode-iOSTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JWTDecode-iOSTests-Bridging-Header.h"; sourceTree = ""; }; 5F0069401B3C828F0048928E /* A0JWTDecodeSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0JWTDecodeSpec.m; sourceTree = ""; }; - 5F0A5E291B9A6D4A005289CF /* JWTDecode.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = JWTDecode.playground; sourceTree = SOURCE_ROOT; }; + 5F0A5E291B9A6D4A005289CF /* JWTDecode.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = JWTDecode.playground; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 5F2496A21D64A91300A1C6E2 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; 5F2496A31D64A91300A1C6E2 /* Cartfile.resolved */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.resolved; sourceTree = ""; }; 5F2496A41D64A91300A1C6E2 /* JWTDecode.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = JWTDecode.podspec; sourceTree = ""; }; diff --git a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme index 84c14cb..3beb14f 100644 --- a/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme +++ b/JWTDecode.xcodeproj/xcshareddata/xcschemes/JWTDecode-iOS.xcscheme @@ -1,7 +1,7 @@ + version = "1.3"> @@ -70,6 +70,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/JWTDecode/JWTDecode.swift b/JWTDecode/JWTDecode.swift index e3c5154..00fcdeb 100644 --- a/JWTDecode/JWTDecode.swift +++ b/JWTDecode/JWTDecode.swift @@ -101,7 +101,11 @@ public struct Claim { if let string = self.string { integer = Int(string) } else { - integer = self.value as? Int + if let double = self.value as? Double { + integer = Int(double) + } else { + integer = self.value as? Int + } } return integer } From 1d9dd4347e73d8a5020d5484aeaade30666ce767 Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Tue, 26 Sep 2017 15:47:37 +0100 Subject: [PATCH 4/6] Add SwiftLint Support Fix lint warnings --- .swiftlint.yml | 26 ++++++++++++++++ JWTDecode.xcodeproj/project.pbxproj | 48 +++++++++++++++++++++++++++++ JWTDecode/JWT.swift | 1 - JWTDecode/JWTDecode.swift | 24 +++++++-------- 4 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..bf4fec6 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,26 @@ +opt_in_rules: # some rules are only opt-in + - empty_count + # Find all the available rules by running: + # swiftlint rules +included: # paths to include during linting. `--path` is ignored if present. + - JWTDecode +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Carthage + - Pods + +# configurable rules can be customized from this configuration file +# rules that have both warning and error levels, can set just the warning level +# implicitly +line_length: 500 +# they can set both implicitly with an array +type_body_length: + - 300 # warning + - 400 # error +type_name: + min_length: 3 # only warning + excluded: # No regex support available for this + - _JWT +identifier_name: + min_length: # only min_length + warning: 3 # only error +reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit) diff --git a/JWTDecode.xcodeproj/project.pbxproj b/JWTDecode.xcodeproj/project.pbxproj index 8e26df9..2dfea44 100644 --- a/JWTDecode.xcodeproj/project.pbxproj +++ b/JWTDecode.xcodeproj/project.pbxproj @@ -360,6 +360,7 @@ 5F0068DE1B3B46240048928E /* Frameworks */, 5F0068DF1B3B46240048928E /* Headers */, 5F0068E01B3B46240048928E /* Resources */, + 5BFB989F1F7A9EC4001FE50D /* SwiftLint */, ); buildRules = ( ); @@ -397,6 +398,7 @@ 5F0069051B3B532E0048928E /* Frameworks */, 5F0069061B3B532E0048928E /* Headers */, 5F0069071B3B532E0048928E /* Resources */, + 5BFB98A01F7A9EEC001FE50D /* SwiftLint */, ); buildRules = ( ); @@ -434,6 +436,7 @@ 918A8E571D63D2E1001F787B /* Frameworks */, 918A8E581D63D2E1001F787B /* Headers */, 918A8E591D63D2E1001F787B /* Resources */, + 5BFB98A11F7A9EF5001FE50D /* SwiftLint */, ); buildRules = ( ); @@ -568,6 +571,51 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 5BFB989F1F7A9EC4001FE50D /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [[ \"${CONFIGURATION}\" = \"Debug\" ]] && [ -z ${CIRCLECI} ] && which swiftlint >/dev/null; then\nswiftlint\nfi"; + }; + 5BFB98A01F7A9EEC001FE50D /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [[ \"${CONFIGURATION}\" = \"Debug\" ]] && [ -z ${CIRCLECI} ] && which swiftlint >/dev/null; then\nswiftlint\nfi"; + }; + 5BFB98A11F7A9EF5001FE50D /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [[ \"${CONFIGURATION}\" = \"Debug\" ]] && [ -z ${CIRCLECI} ] && which swiftlint >/dev/null; then\nswiftlint\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 5F0068DD1B3B46240048928E /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/JWTDecode/JWT.swift b/JWTDecode/JWT.swift index 3a056ba..108c181 100644 --- a/JWTDecode/JWT.swift +++ b/JWTDecode/JWT.swift @@ -35,7 +35,6 @@ public protocol JWT { /// jwt string value var string: String { get } - /// value of `exp` claim if available var expiresAt: Date? { get } /// value of `iss` claim if available diff --git a/JWTDecode/JWTDecode.swift b/JWTDecode/JWTDecode.swift index 00fcdeb..8ecd700 100644 --- a/JWTDecode/JWTDecode.swift +++ b/JWTDecode/JWTDecode.swift @@ -76,15 +76,15 @@ struct DecodedJWT: JWT { */ public struct Claim { - /// raw value of the claim + /// raw value of the claim let value: Any? - /// value of the claim as `String` + /// value of the claim as `String` public var string: String? { return self.value as? String } - /// value of the claim as `Double` + /// value of the claim as `Double` public var double: Double? { let double: Double? if let string = self.string { @@ -95,28 +95,26 @@ public struct Claim { return double } - /// value of the claim as `Int` + /// value of the claim as `Int` public var integer: Int? { let integer: Int? if let string = self.string { integer = Int(string) + } else if let double = self.value as? Double { + integer = Int(double) } else { - if let double = self.value as? Double { - integer = Int(double) - } else { - integer = self.value as? Int - } + integer = self.value as? Int } return integer } - /// value of the claim as `NSDate` + /// value of the claim as `NSDate` public var date: Date? { - guard let timestamp:TimeInterval = self.double else { return nil } + guard let timestamp: TimeInterval = self.double else { return nil } return Date(timeIntervalSince1970: timestamp) } - /// value of the claim as `[String]` + /// value of the claim as `[String]` public var array: [String]? { if let array = value as? [String] { return array @@ -137,7 +135,7 @@ private func base64UrlDecode(_ value: String) -> Data? { let paddingLength = requiredLength - length if paddingLength > 0 { let padding = "".padding(toLength: Int(paddingLength), withPad: "=", startingAt: 0) - base64 = base64 + padding + base64+=padding } return Data(base64Encoded: base64, options: .ignoreUnknownCharacters) } From 3afaeb0d705ed9a77eff0608ad0ff4859dab0d0e Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Tue, 26 Sep 2017 16:13:19 +0100 Subject: [PATCH 5/6] Update README --- README.md | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index de165e1..2d068f5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![License](https://img.shields.io/cocoapods/l/JWTDecode.svg?style=flat-square)](http://cocoadocs.org/docsets/JWTDecode) [![Platform](https://img.shields.io/cocoapods/p/JWTDecode.svg?style=flat-square)](http://cocoadocs.org/docsets/JWTDecode) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square)](https://github.com/Carthage/Carthage) -![Swift 3.0.x](https://img.shields.io/badge/Swift-3.0.x-orange.svg) +![Swift 3.1](https://img.shields.io/badge/Swift-3.1-orange.svg?style=flat-square) This library will help you check [JWT](http://jwt.io/) payload @@ -14,41 +14,46 @@ This library will help you check [JWT](http://jwt.io/) payload ## Requirements -iOS 8+ and Xcode 8 (for Swift 3.0). +- iOS 9 or later +- Xcode 8.3 / 9.0 +- Swift 3.1+ ## Installation -###CocoaPods +#### Carthage -JWTDecode is available through [CocoaPods](http://cocoapods.org). To install -it, simply add the following line to your Podfile: +If you are using Carthage, add the following lines to your `Cartfile`: ```ruby -pod "JWTDecode" +github "auth0/JWTDecode.swift" ~> 2.0 ``` -###Carthage +Then run `carthage bootstrap`. -In your Cartfile add this line +> For more information about Carthage usage, check [their official documentation](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos). -``` -github "auth0/JWTDecode.swift" -``` +#### Cocoapods -###Manual installation +If you are using [Cocoapods](https://cocoapods.org/), add these lines to your `Podfile`: -Download `JWTDecode.framework` from Releases and add it to your project in Xcode. +```ruby +use_frameworks! +pod 'JWTDecode', '~> 2.0' +``` +Then, run `pod install`. -##Usage +> For further reference on Cocoapods, check [their official documentation](http://guides.cocoapods.org/using/getting-started.html). -Just import the framework +## Usage + +Import the framework ```swift import JWTDecode ``` -and decode the token +Decode the token ```swift let jwt = try decode(jwt: token) @@ -56,17 +61,19 @@ let jwt = try decode(jwt: token) ### JWT parts -####Header dictionary +#### Header dictionary + ```swift jwt.header ``` -####Claims in token body +#### Claims in token body + ```swift jwt.body ``` -####Token signature +#### Token signature ```swift jwt.signature ``` From 7555f785b6fe6c7edb7d622bfacc27c97db8be9d Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Wed, 27 Sep 2017 11:41:35 -0300 Subject: [PATCH 6/6] Small style change --- JWTDecode/JWTDecode.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JWTDecode/JWTDecode.swift b/JWTDecode/JWTDecode.swift index 8ecd700..a4f62f4 100644 --- a/JWTDecode/JWTDecode.swift +++ b/JWTDecode/JWTDecode.swift @@ -135,7 +135,7 @@ private func base64UrlDecode(_ value: String) -> Data? { let paddingLength = requiredLength - length if paddingLength > 0 { let padding = "".padding(toLength: Int(paddingLength), withPad: "=", startingAt: 0) - base64+=padding + base64 += padding } return Data(base64Encoded: base64, options: .ignoreUnknownCharacters) }