ForgeRock SDKs

Receive push notifications

You receive Apple push notifications by using the application(_:didReceiveRemoteNotification:fetchCompletionHandler:) method in AppDelegate.

Use the FRAPushHandler.shared.application(:didReceiveRemoteNotification) method to handle RemoteNotification.

The method returns a PushNotification object, which contains the accept and deny methods to handle the authentication request:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    // Once you receive the remote notification, handle it with FRAPushHandler to get the PushNotification object.
    // If RemoteNotification does not contain the expected payload structured from AM, the Authenticator module does not return the PushNotification object.
    if let notification = FRAPushHandler.shared.application(application, didReceiveRemoteNotification: userInfo) {
        // With the PushNotification object, you can either accept or deny
        notification.accept(onSuccess: {

        }) { (error) in

        }
    }
}

The PushNotification class provides the following properties for obtaining values from the payload received in the push notification:

Property Purpose

customPayload

Returns a JSON string containing the values specified in the Custom Payload Attributes property of the Push Sender node.

message

Returns the string specified in the User Message property of the Push Sender node, such as Login attempt from Demo at ForgeRock.

contextInfo

Returns a JSON string containing additional context information when the Share Context info property is enabled in the Push Sender node.

Possible attributes in the JSON string are as follows:

  • location

  • userAgent

  • remoteIp

Ensure you check these attributes for null values, as they depend on being able to be collected by the Device Profile Collector node.

Example:

{
  "location": {
    "latitude": 51.4517076,
    "longitude": -2.5950234
  },
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
  "remoteIp": "198.51.100.23"
}

pushType

Returns a PushType enum value that specifies the type of push notification to present to the user.

This value is based on the configuration of the Push Type property in the Push Sender node.

Possible values are:

PushType.default

Requires the user to tap to accept.

PushType.challenge

Requires the user to select one of three numbers displayed on their device.

This selected number must match the code displayed in the browser for the request to be verified.

PushType.biometric

Requires the user’s biometric authentication to process the notification.

numbersChallengeArray

Returns an array of integers that matches those displayed on the login screen and populates the numbersChallenge attribute, if the Push Type property in the Push Sender node is set to Display Challenge Code.

The class also provides the timeAdded property that contains a timestamp of when the authentication server generated the push authentication payload.

The PushNotification class provides an accept method for handling a PushType.default authentication request:

pushNotification.accept(onSuccess: {
    // called when accepting the push authentication request was successful.
}, onError: { (error) in
    // called when denying the push authentication request, or it has failed.
})

For PushType.challenge authentication requests, use the following accept method that receives the challenge as a parameter:

public func accept(challengeResponse: String,
	onSuccess: @escaping SuccessCallback,
    onError: @escaping ErrorCallback) {}

For PushType.biometric authentication requests, use the following accept method that processes the biometric authentication request:

public func accept(title: String,
	allowDeviceCredentials: Bool,
    onSuccess: @escaping SuccessCallback,
    onError: @escaping ErrorCallback) {}

Use the pushType enum to determine which to call:

if notification.pushType == .challenge {
    notification.accept(challengeResponse: "34", onSuccess: successCallback, onError: errorCallback)
} else if notification.pushType == .biometric {
    notification.accept(title: "title", allowDeviceCredentials: trueonSuccess: successCallback, onError: errorCallback)
} else {
    notification.accept(onSuccess: successCallback, onError: errorCallback)
}
Copyright © 2010-2023 ForgeRock, all rights reserved.