Repository: vapor/jwt-kit (swift)

Issue:
Missing typ field in the header
There must be a `typ: "JWT"` field in the header. At least MapKit is giving a warning about it missing.
And there is no way to modify header, since it is created in `JWTSerializer` which is internal.

Pull request description:
Adds `typ` and `cty` fields to the JWT header (#27, fixes #25, fixes #5).

- Add `typ` header as parameter making "JWT" the default. 

- Allow setting `cty` during JWT signing.

```swift
let signer = JWTSigner.hs256(key: keyData)`
let token = try signer.sign(payload, cty: "twilio-fpa;v=1")
```

Patch:
diff --git a/Sources/JWTKit/JWTSerializer.swift b/Sources/JWTKit/JWTSerializer.swift
index 5df812e8..d6a3c24f 100644
--- a/Sources/JWTKit/JWTSerializer.swift
+++ b/Sources/JWTKit/JWTSerializer.swift
@@ -4,7 +4,9 @@ struct JWTSerializer {
     func sign<Payload>(
         _ payload: Payload,
         using signer: JWTSigner,
-        kid: JWKIdentifier? = nil
+        typ: String = "JWT",
+        kid: JWKIdentifier? = nil,
+        cty: String? = nil
     ) throws -> String
         where Payload: JWTPayload
     {
@@ -14,6 +16,8 @@ struct JWTSerializer {
         // encode header, copying header struct to mutate alg
         var header = JWTHeader()
         header.kid = kid
+        header.typ = typ
+        header.cty = cty
         header.alg = signer.algorithm.name
 
         let headerData = try jsonEncoder.encode(header)
diff --git a/Sources/JWTKit/Signing/JWTSigner.swift b/Sources/JWTKit/Signing/JWTSigner.swift
index 7687d80e..b858a698 100644
--- a/Sources/JWTKit/Signing/JWTSigner.swift
+++ b/Sources/JWTKit/Signing/JWTSigner.swift
@@ -7,11 +7,12 @@ public final class JWTSigner {
     }
 
     public func sign<Payload>(
-        _ payload: Payload
+        _ payload: Payload,
+        cty: String? = nil
     ) throws -> String
         where Payload: JWTPayload
     {
-        try JWTSerializer().sign(payload, using: self, kid: nil)
+        try JWTSerializer().sign(payload, using: self, kid: nil, cty: cty)
     }
 
     public func unverified<Payload>(


Test patch:
diff --git a/Tests/JWTKitTests/JWTKitTests.swift b/Tests/JWTKitTests/JWTKitTests.swift
index b3e70bed..772591f9 100644
--- a/Tests/JWTKitTests/JWTKitTests.swift
+++ b/Tests/JWTKitTests/JWTKitTests.swift
@@ -40,7 +40,7 @@ class JWTKitTests: XCTestCase {
         let exp = ExpirationClaim(value: Date(timeIntervalSince1970: 2_000_000_000))
         let jwt = try JWTSigner.hs256(key: "secret".bytes)
             .sign(ExpirationPayload(exp: exp))
-        XCTAssertEqual(jwt, "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjIwMDAwMDAwMDB9.4W6egHvMSp9bBiGUnE7WhVfXazOfg-ADcjvIYILgyPU")
+        XCTAssertEqual(jwt, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjIwMDAwMDAwMDB9.JgCO_GqUQnbS0z2hCxJLE9Tpt5SMoZObHBxzGBWuTYQ")
     }
 
     func testSigners() throws {