PushNotification
public struct PushNotification : Codable, Identifiable, @unchecked Sendable, CustomStringConvertible
Represents a push notification authentication challenge.
A Push notification contains all the information about an authentication request received via push notification. It includes the notification content, challenge data, expiration information, and response status.
Notification Types
Push notifications can be of different types:
- DEFAULT: Simple approve/deny notification
- CHALLENGE: Notification requiring challenge verification (e.g., number matching)
- BIOMETRIC: Notification requiring biometric authentication
Lifecycle
- Created: Notification is received and stored
- Pending: Waiting for user action
- Approved/Denied: User has responded
- Expired: TTL has elapsed
Usage Example
// Process incoming notification
let notification = try await client.processNotification(userInfo)
// Check if expired
if notification.isExpired {
print("Notification has expired")
return
}
// For challenge notifications, get the numbers
if notification.pushType == .challenge {
let numbers = notification.getNumbersChallenge()
// Display numbers to user
}
// Approve or deny
try await client.approveNotification(notification.id)
Note
Notifications have a time-to-live (TTL) and can expire.-
Unique identifier for this notification.
Declaration
Swift
public let id: String -
The ID of the associated credential.
Declaration
Swift
public let credentialId: String -
Time to live in seconds for this notification. After this period elapses, the notification is considered expired.
Declaration
Swift
public let ttl: Int -
Message ID from the push provider. This is used to correlate the notification with server records.
Declaration
Swift
public let messageId: String -
Optional message to display to the user. This typically contains context about the authentication request (e.g., “Login attempt from Chrome on Windows”).
Declaration
Swift
public let messageText: String? -
Optional additional custom payload data.
Declaration
Swift
public let customPayload: String? -
Optional challenge data (e.g., verification code). Used for CHALLENGE type notifications.
Declaration
Swift
public let challenge: String? -
Optional challenge with numeric format. Typically a comma-separated list of numbers for number matching challenges.
Declaration
Swift
public var numbersChallenge: String? -
Optional cookie for load balancing. Used to route the request to the correct server in PingAM.
Declaration
Swift
public let loadBalancer: String? -
Optional additional context information. In PingAM, this may contain details such as IP address, user agent, location, etc.
Declaration
Swift
public let contextInfo: String? -
The type of push notification (DEFAULT, CHALLENGE, BIOMETRIC).
Declaration
Swift
public let pushType: PushType -
Timestamp when this notification was created locally.
Declaration
Swift
public let createdAt: Date -
Optional timestamp from the server when this notification was sent.
Declaration
Swift
public let sentAt: Date? -
Timestamp when the user responded to this notification.
Declaration
Swift
public var respondedAt: Date? -
Optional additional custom data associated with this notification. This is a map of key-value pairs. The values can be of any type. Note: This is not directly encoded/decoded due to type erasure limitations.
Declaration
Swift
public var additionalData: [String : Any]? -
Whether this notification has been approved by the user.
Declaration
Swift
public var approved: Bool -
Whether this notification is pending (not yet approved or denied).
Declaration
Swift
public var pending: Bool
-
String representation of the push notification type.
Declaration
Swift
public var type: String { get } -
Checks if the user has responded to this notification.
Declaration
Swift
public var responded: Bool { get } -
Checks if this notification has expired. A notification is expired if the elapsed time since creation exceeds the TTL.
Declaration
Swift
public var isExpired: Bool { get }
-
Declaration
Swift
public var description: String { get }
-
init(id:credentialId: ttl: messageId: messageText: customPayload: challenge: numbersChallenge: loadBalancer: contextInfo: pushType: createdAt: sentAt: respondedAt: additionalData: approved: pending: ) Creates a new Push notification.
Declaration
Swift
public init( id: String = UUID().uuidString, credentialId: String, ttl: Int, messageId: String, messageText: String? = nil, customPayload: String? = nil, challenge: String? = nil, numbersChallenge: String? = nil, loadBalancer: String? = nil, contextInfo: String? = nil, pushType: PushType, createdAt: Date = Date(), sentAt: Date? = nil, respondedAt: Date? = nil, additionalData: [String: Any]? = nil, approved: Bool = false, pending: Bool = true )Parameters
idUnique identifier for this notification. Defaults to a new UUID.
credentialIdThe ID of the associated credential.
ttlTime to live in seconds for this notification.
messageIdMessage ID from the push provider.
messageTextOptional message to display to the user.
customPayloadOptional additional custom payload data.
challengeOptional challenge data.
numbersChallengeOptional numeric challenge.
loadBalancerOptional load balancer cookie.
contextInfoOptional context information.
pushTypeThe type of push notification.
createdAtTimestamp when created. Defaults to current date.
sentAtOptional timestamp when sent by server.
respondedAtOptional timestamp when responded.
additionalDataOptional additional custom data.
approvedWhether approved. Defaults to false.
pendingWhether pending. Defaults to true.
-
Get numbers used for push challenge.
For CHALLENGE type notifications, this method parses the
numbersChallengestring (expected to be a comma-separated list of numbers) and returns them as an array of integers.Example
// If numbersChallenge is "12, 34, 56" let numbers = notification.getNumbersChallenge() // numbers = [12, 34, 56]Declaration
Swift
public func getNumbersChallenge() -> [Int]Return Value
The numbers as an array of Int. Returns empty array if numbersChallenge is not available or cannot be parsed.
-
Declaration
Swift
public init(from decoder: Decoder) throws -
Declaration
Swift
public func encode(to encoder: Encoder) throws
View on GitHub