Before performing authentication or document signing, you must fetch the cross-device session sent from another device as described in Create a Cross-Device Session. Depending on how the session was initiated, you can fetch it using one of the three options described in the sections below.
## Deep Linking
To fetch the session via deep linking, use one of the following methods:
- getCrossDeviceSessionFromAppLink for Android
- getCrossDeviceSessionFromUniversalLinkURL for iOS
- getCrossDeviceSessionFromLink Flutter
intent.data?.let { appLink ->
miraclTrust.getCrossDeviceSessionFromAppLink(
appLink = appLink,
resultHandler = { result ->
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
// Cannot obtain CrossDeviceSession due to an error.
}
}
}
)
}
intent.data?.let { appLink ->
val result = miraclTrust.getCrossDeviceSessionFromAppLink(appLink)
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
val error = result.value
// Cannot obtain CrossDeviceSession due to an error.
}
}
}
Uri appLink = getIntent().getData();
if (appLink != null) {
miraclTrust.getCrossDeviceSessionFromAppLink(
appLink,
result -> {
if (result instanceof MIRACLSuccess) {
CrossDeviceSession crossDeviceSession =
((MIRACLSuccess<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Use the crossDeviceSession to authenticate or sign.
} else {
CrossDeviceSessionException error =
((MIRACLError<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Cannot obtain CrossDeviceSession due to an error.
}
}
);
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard let universalLinkURL = userActivity.webpageURL else {
return
}
MIRACLTrust
.getInstance()
.getCrossDeviceSessionFromUniversalLinkURL(
universalLinkURL: universalLinkURL
) { crossDeviceSession, error in
// Use the cross device session or handle the error appropriately.
}
}
-(void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
if(userActivity.webpageURL == nil) {
return;
}
NSURL *universalLinkURL = userActivity.webpageURL;
[[MIRACLTrust getInstance]
getCrossDeviceSessionFromUniversalLinkURL:universalLinkURL completionHandler:^(
CrossDeviceSession *crossDeviceSession,
NSError *error
) {
// Use the cross device session or handle the error appropriately.
}];
}
Promise:
try {
const crossDeviceSession = await mcl.getCrossDeviceSessionFromLink(appLink);
console.log(crossDeviceSession);
} catch (err) {
// Handle any potential errors
}
Callback:
mcl.getCrossDeviceSessionFromLink(appLink, function (err, crossDeviceSession) {
if (err) {
// Handle any potential errors
}
console.log(crossDeviceSession);
});
try {
final crossDeviceSession = await miraclTrust.getCrossDeviceSessionFromLink(link);
// Use the crossDeviceSession to authenticate or sign.
} on CrossDeviceSessionException catch(e) {
// Handle the exception here.
}
## QR code
To fetch the session via QR code, use the getCrossDeviceSessionFromQRCode
method for
Android,
iOS
or
Flutter.
miraclTrust.getCrossDeviceSessionFromQRCode(
qrCode = qrCode,
resultHandler = { result ->
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
val error = result.value
// Cannot obtain CrossDeviceSession due to an error.
}
}
}
)
val result = miraclTrust.getCrossDeviceSessionFromQRCode(qrCode)
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
val error = result.value
// Cannot obtain CrossDeviceSession due to an error.
}
}
miraclTrust.getCrossDeviceSessionFromQRCode(
qrCode,
result -> {
if (result instanceof MIRACLSuccess) {
CrossDeviceSession crossDeviceSession =
((MIRACLSuccess<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Use the crossDeviceSession to authenticate or sign.
} else {
CrossDeviceSessionException error =
((MIRACLError<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Cannot obtain CrossDeviceSession due to an error.
}
}
);
MIRACLTrust
.getInstance()
.getCrossDeviceSessionFromQRCode(
qrCode: <#QR code taken from a MIRACL Trust page#>
) { crossDeviceSession, error in
// Use the cross device session or handle the error appropriately.
}
[[MIRACLTrust getInstance]
getCrossDeviceSessionFromQRCode:<#QR code taken from a MIRACL Trust page#>
completionHandler:^(
CrossDeviceSession * crossDeviceSession,
NSError * error
) {
// Use the cross device session or handle the error appropriately.
}];
try {
const crossDeviceSession = await mcl.getCrossDeviceSessionFromQRCode(qrCode);
console.log(crossDeviceSession);
} catch (err) {
// Handle any potential errors
}
Callback:
mcl.getCrossDeviceSessionFromQRCode(qrCode, function (err, crossDeviceSession) {
if (err) {
// Handle any potential errors
}
console.log(crossDeviceSession);
});
try {
final crossDeviceSession = await miraclTrust.getCrossDeviceSessionFromQRCode(qrCode);
// Use the crossDeviceSession to authenticate or sign.
} on CrossDeviceSessionException catch(e) {
// Handle the exception here.
}
## Push notification
To fetch the session via push notification, use the
getCrossDeviceSessionFromNotificationPayload method for
Android,
iOS
or
Flutter.
val payload = remoteMessage.data
miraclTrust.getCrossDeviceSessionFromNotificationPayload(
payload = payload,
resultHandler = { result ->
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
val error = result.value
// Cannot obtain CrossDeviceSession due to an error.
}
}
}
)
val payload = remoteMessage.data
val result = miraclTrust.getCrossDeviceSessionFromNotificationPayload(payload)
when (result) {
is MIRACLSuccess -> {
val crossDeviceSession = result.value
// Use the crossDeviceSession to authenticate or sign.
}
is MIRACLError -> {
val error = result.value
// Cannot obtain CrossDeviceSession due to an error.
}
}
Map<String, String> payload = remoteMessage.getData();
miraclTrust.getCrossDeviceSessionFromNotificationPayload(
payload,
result -> {
if (result instanceof MIRACLSuccess) {
CrossDeviceSession crossDeviceSession =
((MIRACLSuccess<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Use the crossDeviceSession to authenticate or sign.
} else {
CrossDeviceSessionException error =
((MIRACLError<CrossDeviceSession, CrossDeviceSessionException>)
result).getValue();
// Cannot obtain CrossDeviceSession due to an error.
}
}
);
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
let pushPayload = response.notification.request.content.userInfo
MIRACLTrust
.getInstance()
.getCrossDeviceSessionFromPushNotificationPayload(
pushNotificationPayload: pushPayload
) { crossDeviceSession, error in
// Use the cross device session or handle the error appropriately.
}
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
NSDictionary *pushPayload = notification.request.content.userInfo;
[[MIRACLTrust getInstance]
getCrossDeviceSessionFromPushNotificationPayload:pushPayload
completionHandler:^(
CrossDeviceSession * crossDeviceSession, NSError *error
) {
// Use the cross device session or handle the error appropriately.
}];
}
Promise:
try {
const crossDeviceSession =
await mcl.getCrossDeviceSessionFromNotificationPayload(payload);
console.log(crossDeviceSession);
} catch (err) {
// Handle any potential errors
}
Callback:
mcl.getCrossDeviceSessionFromNotificationPayload(payload, function (err, crossDeviceSession) {
if (err) {
// Handle any potential errors
}
console.log(crossDeviceSession);
});
try {
final crossDeviceSession = await miraclTrust.getCrossDeviceSessionFromPushNotificationPayload(payload);
// Use the crossDeviceSession to authenticate or sign.
} on CrossDeviceSessionException catch(e) {
// Handle the exception here.
}
After fetching the cross-device session, you can proceed with either
authentication or document signing. To determine which operation the session is
intended for, check its type property.