Hyphen uses Firebase Messaging to send a 2-factor authorization request to the user's device. Without using SDK, your client needs to handle and implement the data sent along with the push message and display appropriate UI to the user.
Common Data Format
In the push message, there are fields that indicate whether the message is from Hyphen and which type is it. The actual data is always encoded as JSON and wrapped in a hyphen:data key in the push message.
Key
Description
Example
hyphen:type
The message type
"2fa-request"
hyphen:data
JSON-encoded data object
"{\"twoFactorAuth\":...}"
For example, on iOS, the data can be decoded like this:
struct TwoFactorAuthStatusPayload: Codable { ...}
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
guard let msgType = userInfo["hyphen:type"] as? String,
let msgDataString = userInfo["hyphen:data"] as? String,
let msgData = msgDataString.data(using: .utf8) else {
// The payload was not a string or the string could not be converted to Data
completionHandler(.failed)
return
}
do {
let decoder = JSONDecoder()
switch msgType {
case "2fa-status-change":
let myData = try decoder.decode(TwoFactorAuthStatusPayload.self, from: msgData)
completionHandler(.myData)
}
} catch {
print("Decoding error: \(error)")
completionHandler(.failed)
}
}
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import kotlinx.serialization.*
import kotlinx.serialization.json.*
class YourFCMService: FirebaseMessagingService {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (remoteMessage.data.isNotEmpty()) {
val type = remoteMessage.data["hyphen:type"]
val hyphenData = remoteMessage.data["hyphen:data"]
val json = Json {}
if (type == "2fa-status-change") {
val myData = json.decodeToString<TwoFactorAuthStatusPayload>(hyphenData)
// write your logic
}
}
}
}
List of Push Message Data
2FA Request (On Destination Device)
This message is being sent to the destination device which approves/denies the 2FA request (e.g. the existing device having a key registered). It's sent as a notification with the highest priority.
Data Format
The hyphen:type is "2fa-request" .
Key
Description
Example
twoFactorAuth
TwoFactorAuthStatus object used same as REST API's.
This message is being sent to the source device which requested the 2FA (e.g. the new device tries to sign in). It's sent as a Background Update push without any notification.
Data Format
The hyphen:type is "2fa-status-change" .
Key
Description
Example
twoFactorAuth
TwoFactorAuthStatus object used same as REST API's.