-
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathAPNSURLSessionClientConfiguration.swift
More file actions
67 lines (59 loc) 路 2.55 KB
/
Copy pathAPNSURLSessionClientConfiguration.swift
File metadata and controls
67 lines (59 loc) 路 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//===----------------------------------------------------------------------===//
//
// This source file is part of the APNSwift open source project
//
// Copyright (c) 2022 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 APNSCore
@preconcurrency import Crypto
/// The configuration of an ``APNSURLSessionClient``.
public struct APNSURLSessionClientConfiguration {
/// The authentication method used by the ``APNSURLSessionClient``.
public enum AuthenticationMethod {
case jwt(privateKey: P256.Signing.PrivateKey, teamIdentifier: String, keyIdentifier: String)
}
/// The environment used by the ``APNSURLSessionClient``.
public var environment: APNSEnvironment
/// Type-erased access to the generic ``APNSAuthenticationTokenManager``.
///
/// The token manager is generic over its ``Clock``, but this configuration is not, so the
/// concrete, caller-injected clock is captured in this closure at ``init`` time rather than
/// stored as a typed property.
private let nextValidTokenClosure: @Sendable () async throws -> String
internal func nextValidToken() async throws -> String {
try await nextValidTokenClosure()
}
/// Initializes a new ``APNSClient.Configuration``.
///
/// - Parameters:
/// - environment: The environment used by the ``APNSURLSessionClient``.
/// - privateKey: The private encryption key obtained through the developer portal.
/// - keyIdentifier: The private encryption key identifier obtained through the developer portal.
/// - teamIdentifier: The team id.
/// - clock: The clock used to determine when a generated authentication token has expired.
public init<APNSClock: Clock>(
environment: APNSEnvironment,
privateKey: P256.Signing.PrivateKey,
keyIdentifier: String,
teamIdentifier: String,
clock: APNSClock = ContinuousClock()
) where APNSClock.Duration == Duration {
self.environment = environment
let authenticationTokenManager = APNSAuthenticationTokenManager(
privateKey: privateKey,
teamIdentifier: teamIdentifier,
keyIdentifier: keyIdentifier,
clock: clock
)
self.nextValidTokenClosure = {
try await authenticationTokenManager.nextValidToken
}
}
}