Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial provider token fixes. * Fix tests. * UPdate for API Breakage. * Updates to bearertoken * Cleanup tests. * Revert Old deprecated APNSwiftBearer to its original form * Remove nio. * Add deprecration. * Remove old signature. * Add private initializier method. * Update to convinience init. * Update license header.
- Loading branch information
1 parent
0699bb1
commit 46e602a
Showing
10 changed files
with
148 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the APNSwift open source project | ||
// | ||
// Copyright (c) 2019 the APNSwift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of APNSwift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
import Foundation | ||
import NIO | ||
internal final class APNSwiftBearerTokenFactory { | ||
var updateTask: RepeatedTask? | ||
let eventLoop: EventLoop | ||
var currentBearerToken: String | ||
var cancelled = false | ||
let configuration: APNSwiftConfiguration | ||
|
||
init(eventLoop: EventLoop, configuration: APNSwiftConfiguration) throws { | ||
self.eventLoop = eventLoop | ||
self.eventLoop.assertInEventLoop() | ||
self.configuration = configuration | ||
self.currentBearerToken = try APNSwiftBearerTokenFactory.makeNewBearerToken(configuration: configuration) | ||
self.updateTask = eventLoop.scheduleRepeatedTask(initialDelay: .minutes(55), delay: .minutes(55)) { task in | ||
self.currentBearerToken = try APNSwiftBearerTokenFactory.makeNewBearerToken(configuration: configuration) | ||
} | ||
} | ||
|
||
func cancel() { | ||
self.eventLoop.assertInEventLoop() | ||
self.cancelled = true | ||
self.updateTask?.cancel() | ||
self.updateTask = nil | ||
} | ||
|
||
deinit { | ||
assert(self.cancelled, "APNSwiftBearerTokenFactory not closed on deinit. You must call APNSwiftBearerTokenFactory.close when you no longer need it to make sure the library can discard the resources") | ||
} | ||
static func makeNewBearerToken(configuration: APNSwiftConfiguration) throws -> String { | ||
let jwt = APNSwiftJWT(keyID: configuration.keyIdentifier, teamID: configuration.teamIdentifier, issueDate: Date()) | ||
let digestValues = try jwt.getDigest() | ||
var signature = try configuration.signer.sign(digest: digestValues.fixedDigest) | ||
let data = signature.readData(length: signature.readableBytes)! | ||
return digestValues.digest + "." + data.base64EncodedURLString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.