From d788d0724b182202de9e53d36ccab50c789d0680 Mon Sep 17 00:00:00 2001 From: Jochen Holzer Date: Sat, 20 Jan 2018 12:26:28 +0100 Subject: [PATCH 1/4] make claims readable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As described in issue https://github.com/kylef/JSONWebToken.swift/issues/69 in some cases access to the raw json data is needed. Therefore „claims“ should be exposed. --- Sources/JWT/ClaimSet.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/JWT/ClaimSet.swift b/Sources/JWT/ClaimSet.swift index 114c04e..69f3911 100644 --- a/Sources/JWT/ClaimSet.swift +++ b/Sources/JWT/ClaimSet.swift @@ -15,7 +15,7 @@ func parseTimeInterval(_ value: Any?) -> Date? { } public struct ClaimSet { - var claims: [String: Any] + public private (set) var claims: [String: Any] public init(claims: [String: Any]? = nil) { self.claims = claims ?? [:] From 793c5d584137497a28e876577ceddc8dca43650d Mon Sep 17 00:00:00 2001 From: Jochen Holzer Date: Sat, 20 Jan 2018 12:40:55 +0100 Subject: [PATCH 2/4] change setter of "claims" to internal --- Sources/JWT/ClaimSet.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/JWT/ClaimSet.swift b/Sources/JWT/ClaimSet.swift index 69f3911..a35e73d 100644 --- a/Sources/JWT/ClaimSet.swift +++ b/Sources/JWT/ClaimSet.swift @@ -15,7 +15,7 @@ func parseTimeInterval(_ value: Any?) -> Date? { } public struct ClaimSet { - public private (set) var claims: [String: Any] + public internal (set) var claims: [String: Any] public init(claims: [String: Any]? = nil) { self.claims = claims ?? [:] From e4aad608d39dc946eff6724f4a9f9aeafbce27e9 Mon Sep 17 00:00:00 2001 From: Jochen Holzer Date: Sat, 20 Jan 2018 13:00:46 +0100 Subject: [PATCH 3/4] add fork description and cocoapods installation instruction --- README.md | 96 +++---------------------------------------------------- 1 file changed, 5 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index ce1db66..8b2d054 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,14 @@ # JSON Web Token -[![Build Status](http://img.shields.io/travis/kylef/JSONWebToken.swift/master.svg?style=flat)](https://travis-ci.org/kylef/JSONWebToken.swift) - -Swift implementation of [JSON Web Token](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32). +Fork of https://github.com/kylef/JSONWebToken.swift that resolves the issue "Get raw claim set data" ((https://github.com/kylef/JSONWebToken.swift/issues/69) ## Installation -Swift Pacakage Manager is the recommended installation method for JSONWebToken, [CocoaPods](http://cocoapods.org/) is also supported. - -```ruby -pod 'JSONWebToken' -``` - -**NOTE:** *Carthage may be supported, however support will not be provided for this installation method, use at your own risk if you know how it works.* - -## Usage - -```swift -import JWT -``` - -### Encoding a claim - -```swift -JWT.encode(claims: ["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!)) -``` - -#### Encoding a claim set - -```swift -var claims = ClaimSet() -claims.issuer = "fuller.li" -claims.issuedAt = Date() -claims["custom"] = "Hi" - -JWT.encode(claims: claims, algorithm: .hs256("secret".data(using: .utf8))) -``` - -#### Building a JWT with the builder pattern - -```swift -JWT.encode(.hs256("secret".data(using: .utf8))) { builder in - builder.issuer = "fuller.li" - builder.issuedAt = Date() - builder["custom"] = "Hi" -} -``` - -### Decoding a JWT - -When decoding a JWT, you must supply one or more algorithms and keys. - -```swift -do { - let claims: ClaimSet = try JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", algorithm: .hs256("secret".data(using: .utf8)!)) - print(claims) -} catch { - print("Failed to decode JWT: \(error)") -} -``` - -When the JWT may be signed with one out of many algorithms or keys: - -```swift -try JWT.decode("eyJh...5w", algorithms: [ - .hs256("secret".data(using: .utf8)!), - .hs256("secret2".data(using: .utf8)!), - .hs512("secure".data(using: .utf8)!) -]) -``` - -You might also want to give your iat, exp and nbf checks some kind of leeway to account for skewed clocks. You can do this by passing a `leeway` parameter like this: - -```swift -try JWT.decode("eyJh...5w", algorithm: .hs256("secret".data(using: .utf8)!), leeway: 10) -``` - -#### Supported claims - -The library supports validating the following claims: - -- Issuer (`iss`) Claim -- Expiration Time (`exp`) Claim -- Not Before (`nbf`) Claim -- Issued At (`iat`) Claim -- Audience (`aud`) Claim - -### Algorithms - -This library supports the following algorithms: - -- `none` - Unsecured JWTs -- `hs256` - HMAC using SHA-256 hash algorithm (default) -- `hs384` - HMAC using SHA-384 hash algorithm -- `hs512` - HMAC using SHA-512 hash algorithm +Use cocoapods [CocoaPods](http://cocoapods.org/) and add the following to your Podfile. + pod 'JSONWebToken', :git => 'https://github.com/Wooder/JSONWebToken.swift.git' + + ## License JSONWebToken is licensed under the BSD license. See [LICENSE](LICENSE) for more info. From c9e55d9ceacd5865c8281667c8852956959b6e2f Mon Sep 17 00:00:00 2001 From: Jochen Holzer Date: Mon, 22 Jan 2018 11:24:47 +0100 Subject: [PATCH 4/4] update pod example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b2d054..9ef1778 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Fork of https://github.com/kylef/JSONWebToken.swift that resolves the issue "Get Use cocoapods [CocoaPods](http://cocoapods.org/) and add the following to your Podfile. - pod 'JSONWebToken', :git => 'https://github.com/Wooder/JSONWebToken.swift.git' + pod 'JSONWebToken', :git => 'https://github.com/Wooder/JSONWebToken.swift.git', :branch => '2.2.0-fix-claimset' ## License