Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Few changes required for VaporJWT
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijs2704 committed Oct 31, 2016
1 parent 65f90a2 commit 0e8abfa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/VaporAPNS/VaporAPNS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ open class VaporAPNS {
let headers = self.requestHeaders(for: message)
var curlHeaders: UnsafeMutablePointer<curl_slist>?
if !options.usesCertificateAuthentication {
let decodedKey = options.privateKey!
let privateKey = options.privateKey!

let jwt = try! JWT(additionalHeaders: [KeyID(options.keyId!)],
payload: Node([IssuerClaim(options.teamId!),
IssuedAtClaim()]),
encoding: Base64URLEncoding(),
signer: ES256(key: decodedKey))
signer: ES256(encodedKey: privateKey))

let tokenString = try! jwt.createToken()

let publicKey = options.publicKey!

do {
let jwt2 = try JWT(token: tokenString, encoding: Base64URLEncoding())
let verified = try jwt2.verifySignatureWith(ES256(key: publicKey))
let verified = try jwt2.verifySignatureWith(ES256(encodedKey: publicKey))
if !verified {
return Result.error(apnsId: message.messageId, deviceToken: deviceToken, error: .invalidSignature)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/VaporAPNSTests/VaporAPNSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class VaporAPNSTests: XCTestCase { // TODO: Set this up so others can test this
let jwt = try! JWT(
additionalHeaders: [KeyID("E811E6AE22")],
payload: Node([IssuerClaim("D86BEC0E8B"), IssuedAtClaim()]),
signer: ES256(key: "ALEILVyGWnbBaSaIFDsh0yoZaK+Ej0po/55jG2FR6u6C"))
signer: ES256(encodedKey: "ALEILVyGWnbBaSaIFDsh0yoZaK+Ej0po/55jG2FR6u6C"))

let tokenString = try! jwt.createToken()

do {
let jwt2 = try JWT(token: tokenString)
let verified = try jwt2.verifySignatureWith(ES256(key: "BKqKwB6hpXp9SzWGt3YxnHgCEkcbS+JSrhoqkeqru/Nf62MeE958RIiKYsLFA/czdE7ThCt46azneU0IBnMCuQU="))
let verified = try jwt2.verifySignatureWith(ES256(encodedKey: "BKqKwB6hpXp9SzWGt3YxnHgCEkcbS+JSrhoqkeqru/Nf62MeE958RIiKYsLFA/czdE7ThCt46azneU0IBnMCuQU="))
XCTAssertTrue(verified)
} catch {
print(error)
Expand Down

0 comments on commit 0e8abfa

Please sign in to comment.