createRestoreCredential method
- RegisterRequestType request, {
- bool isCloudBackupEnabled = true,
Creates an Android restore credential (restore key) and stores it on the device.
Restore keys let Android sign the user in silently on a new device. They
are WebAuthn credentials, so request is the same
PublicKeyCredentialCreationOptions your relying party server produces
for register, and the returned RegisterResponseType is verified and
stored by the server exactly like a passkey. Nothing is shown to the user.
isCloudBackupEnabled backs the restore key up to the cloud when the
device has end-to-end encrypted backup (Google backup plus a screen lock)
and stores it locally otherwise, so it still moves with a cable transfer.
Pass false to always keep it local.
Restore credentials only exist on Android 9 (API 28) and above with Google Play services. Everywhere else this throws RestoreCredentialUnsupportedException.
Implementation
@override
Future<RegisterResponseType> createRestoreCredential(
RegisterRequestType request, {
bool isCloudBackupEnabled = true,
}) async {
if (debugMode) {
await _doctor?.check(request.relyingParty.id);
}
try {
_isValidChallenge(request.challenge);
_isValidUserID(request.user.id);
for (final credential in request.excludeCredentials) {
_isValidCredentialID(credential.id);
}
return await _platform.createRestoreCredential(
request,
isCloudBackupEnabled: isCloudBackupEnabled,
);
} on PlatformException catch (e, stackTrace) {
_mapRestoreCredentialException(e, stackTrace);
}
}