You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// A configuration object specifying the contact information along with the keys that your application server identifies itself with.
13
+
///
14
+
/// The ``primaryKey``, when priovided, will always be used for new subscriptions when ``WebPushManager/nextVAPIDKeyID`` is called. If omitted, one of the keys in ``keys`` will be randomely chosen instead.
15
+
///
16
+
/// ``deprecatedKeys`` that you must stull support for older subscribers, but don't wish to use when registering new subscribers, may also be specified.
17
+
///
18
+
/// To reduce implementation complexity, it is recommended to only use a single ``primaryKey``, though this key should be stored with subscribers as ``Subscriber`` encourages you to do so that you can deprecate it in the future should it ever leak.
19
+
///
20
+
/// ## Codable
21
+
///
22
+
/// VAPID configurations should ideally be generated a single time and shared across all instances of your application server, across runs. To facilitate this, you can encode and decode a configuration to load it at runtime rather than instanciate a new one every time:
23
+
/// ```swift
24
+
/// // TODO: Load this data from .env or from file system
25
+
/// let configurationData = Data(#" {"contactInformation":"https://example.com","expirationDuration":79200,"primaryKey":"6PSSAJiMj7uOvtE4ymNo5GWcZbT226c5KlV6c+8fx5g=","validityDuration":72000} "#.utf8)
26
+
/// let vapidConfiguration = try JSONDecoder().decode(VAPID.Configuration.self, from: configurationData)
27
+
/// ```
28
+
///
29
+
/// - SeeAlso: [Generating Keys](https://github.com/mochidev/swift-webpush?tab=readme-ov-file#generating-keys): Keys can also be generated by our `vapid-key-generator` helper tool.
12
30
publicstructConfiguration:Hashable,Sendable{
13
31
/// The VAPID key that identifies the push service to subscribers.
14
32
///
15
-
/// This key should be shared by all instances of your push service, and should be kept secure. Rotating this key is not recommended as you'll lose access to subscribers that registered against it.
16
-
///
17
-
/// Some implementations will choose to use different keys per subscriber. In that case, choose to provide a set of keys instead.
33
+
/// If not provided, a key from ``keys`` will be used instead.
/// The contact information an administrator of a push service may use to contact you in the case of an issue.
21
49
publicvarcontactInformation:ContactInformation
50
+
51
+
/// The number of seconds before a cached authentication header signed by this configuration fully expires.
52
+
///
53
+
/// This value must be 24 hours or less, and it conservatively set to 22 hours by default to account for clock drift between your applications erver and push services.
22
54
publicvarexpirationDuration:Duration
55
+
56
+
/// The number of seconds before a cached authentication header signed by this configuration is renewed.
57
+
///
58
+
/// This valus must be less than ``expirationDuration``, and is set to 20 hours by default as an adequate compromise between re-usability and key over-use.
23
59
publicvarvalidityDuration:Duration
24
60
61
+
/// Initialize a configuration with a single primary key.
62
+
/// - Parameters:
63
+
/// - key: The primary key to use when introducing your application server during registration.
64
+
/// - deprecatedKeys: Suppoted, but deprecated, keys to use during push delivery if a subscriber requires them.
65
+
/// - contactInformation: The contact information an administrator of a push service may use to contact you in the case of an issue.
66
+
/// - expirationDuration: The number of seconds before a cached authentication header signed by this configuration fully expires.
67
+
/// - validityDuration: The number of seconds before a cached authentication header signed by this configuration is renewed.
/// Initialize a configuration with a multiple VAPID keys.
86
+
///
87
+
/// Use this initializer _only_ if you wish to implement more complicated key rotation if you believe keys may be leaked at a higher rate than usual. In all other cases, it is highly recommended to use ``init(key:deprecatedKeys:contactInformation:expirationDuration:validityDuration:)`` instead to supply a singly primary key and keep it secure.
88
+
/// - Parameters:
89
+
/// - primaryKey: The optional primary key to use when introducing your application server during registration.
90
+
/// - keys: The set of valid keys to choose from when identifying the applications erver to new registrations.
91
+
/// - deprecatedKeys: Suppoted, but deprecated, keys to use during push delivery if a subscriber requires them.
92
+
/// - contactInformation: The contact information an administrator of a push service may use to contact you in the case of an issue.
93
+
/// - expirationDuration: The number of seconds before a cached authentication header signed by this configuration fully expires.
94
+
/// - validityDuration: The number of seconds before a cached authentication header signed by this configuration is renewed.
0 commit comments