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

  1. Created: Notification is received and stored
  2. Pending: Waiting for user action
  3. Approved/Denied: User has responded
  4. 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.

Properties

  • id

    Unique identifier for this notification.

    Declaration

    Swift

    public let id: String
  • The ID of the associated credential.

    Declaration

    Swift

    public let credentialId: String
  • ttl

    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

Computed Properties

  • 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 }

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }

Initializers

  • 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

    id

    Unique identifier for this notification. Defaults to a new UUID.

    credentialId

    The ID of the associated credential.

    ttl

    Time to live in seconds for this notification.

    messageId

    Message ID from the push provider.

    messageText

    Optional message to display to the user.

    customPayload

    Optional additional custom payload data.

    challenge

    Optional challenge data.

    numbersChallenge

    Optional numeric challenge.

    loadBalancer

    Optional load balancer cookie.

    contextInfo

    Optional context information.

    pushType

    The type of push notification.

    createdAt

    Timestamp when created. Defaults to current date.

    sentAt

    Optional timestamp when sent by server.

    respondedAt

    Optional timestamp when responded.

    additionalData

    Optional additional custom data.

    approved

    Whether approved. Defaults to false.

    pending

    Whether pending. Defaults to true.

Action Methods

  • Mark this notification as approved.

    This method updates the notification state to indicate that the user has approved the authentication request. It sets approved to true, pending to false, and records the response timestamp.

    Declaration

    Swift

    public mutating func markApproved()
  • Mark this notification as denied.

    This method updates the notification state to indicate that the user has denied the authentication request. It sets approved to false, pending to false, and records the response timestamp.

    Declaration

    Swift

    public mutating func markDenied()
  • Get numbers used for push challenge.

    For CHALLENGE type notifications, this method parses the numbersChallenge string (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.

Codable

  • Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws