Skip to content

Commit ce7285f

Browse files
committed
feat: Document new ClaimSet
Closes #45
1 parent 30cb9ea commit ce7285f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# JSON Web Token Changelog
22

3+
## Master
4+
5+
### Enhancements
6+
7+
- Introduces a new `ClaimSet` structure. The structure can be returned from
8+
`decode` providing you convenience accessors. `encode` will now accept a
9+
`ClaimSet`.
10+
11+
312
## 2.0.2
413

514
### Enhancements

README.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ import JWT
2121
### Encoding a claim
2222

2323
```swift
24-
JWT.encode(["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!))
24+
JWT.encode(claims: ["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!))
25+
```
26+
27+
#### Encoding a claim set
28+
29+
```swift
30+
var claims = ClaimSet()
31+
claims.issuer = "fuller.li"
32+
claims.issuedAt = Date()
33+
claims["custom"] = "Hi"
34+
35+
JWT.encode(claims: claims, algorithm, algorithm: .hs256("secret".data(using: .utf8)))
2536
```
2637

2738
#### Building a JWT with the builder pattern
@@ -40,8 +51,8 @@ When decoding a JWT, you must supply one or more algorithms and keys.
4051

4152
```swift
4253
do {
43-
let payload = try JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", algorithm: .hs256("secret".data(using: .utf8)!))
44-
print(payload)
54+
let claims = try JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", algorithm: .hs256("secret".data(using: .utf8)!))
55+
print(claims)
4556
} catch {
4657
print("Failed to decode JWT: \(error)")
4758
}
@@ -79,4 +90,3 @@ This library supports the following algorithms:
7990
## License
8091

8192
JSONWebToken is licensed under the BSD license. See [LICENSE](LICENSE) for more info.
82-

0 commit comments

Comments
 (0)