|
| 1 | +// Copyright 2013 The Flutter Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/foundation.dart'; |
| 6 | + |
| 7 | +/// An exception thrown by the plugin when there is authentication failure, or |
| 8 | +/// some other error. |
| 9 | +@immutable |
| 10 | +class LocalAuthException implements Exception { |
| 11 | + /// Creates a new exception with the given information. |
| 12 | + const LocalAuthException({ |
| 13 | + required this.code, |
| 14 | + this.description, |
| 15 | + this.details, |
| 16 | + }); |
| 17 | + |
| 18 | + /// The type of failure. |
| 19 | + final LocalAuthExceptionCode code; |
| 20 | + |
| 21 | + /// A human-readable description of the failure. |
| 22 | + final String? description; |
| 23 | + |
| 24 | + /// Any additional details about the failure. |
| 25 | + final Object? details; |
| 26 | + |
| 27 | + @override |
| 28 | + String toString() => |
| 29 | + '${objectRuntimeType(this, 'LocalAuthException')}(code ${code.name}, $description, $details)'; |
| 30 | +} |
| 31 | + |
| 32 | +/// Types of [LocalAuthException]s, as indicated by [LocalAuthException.code]. |
| 33 | +/// |
| 34 | +/// Adding new values to this enum in the future will *not* be considered a |
| 35 | +/// breaking change, so clients should not assume they can exhaustively match |
| 36 | +/// exception codes. Clients should always include a default or other fallback. |
| 37 | +enum LocalAuthExceptionCode { |
| 38 | + /// An authentication operation is already in progress, and has not completed. |
| 39 | + /// |
| 40 | + /// A new authentication cannot be started while the Future for a previous |
| 41 | + /// authentication is still outstanding. |
| 42 | + authInProgress, |
| 43 | + |
| 44 | + /// UI needs to be displayed, but could not be. |
| 45 | + /// |
| 46 | + /// For example, this can be returned on Android if a call tries to show UI |
| 47 | + /// when no Activity is available. |
| 48 | + uiUnavailable, |
| 49 | + |
| 50 | + /// The operation was canceled by the user. |
| 51 | + userCanceled, |
| 52 | + |
| 53 | + /// The operation was canceled due to a device-specific timeout. |
| 54 | + timeout, |
| 55 | + |
| 56 | + /// The operation was canceled by a system event. |
| 57 | + /// |
| 58 | + /// For example, on mobile this may be returned if the application is |
| 59 | + /// backgrounded during authentication. |
| 60 | + systemCanceled, |
| 61 | + |
| 62 | + /// The device has no credentials configured. |
| 63 | + /// |
| 64 | + /// For example, on mobile this would be returned if the device has no |
| 65 | + /// enrolled biometrics and no fallback authentication mechanism set such as |
| 66 | + /// a passcode, pin, or pattern. |
| 67 | + noCredentialsSet, |
| 68 | + |
| 69 | + /// The device is capable of biometric authentication, but no biometrics are |
| 70 | + /// enrolled. |
| 71 | + noBiometricsEnrolled, |
| 72 | + |
| 73 | + /// The device does not have biometric hardware. |
| 74 | + noBiometricHardware, |
| 75 | + |
| 76 | + /// The device has, or can have, biometric hardware, but none is currently |
| 77 | + /// available. |
| 78 | + /// |
| 79 | + /// Examples include: |
| 80 | + /// - Hardware that is currently in use by another application. |
| 81 | + /// - Devices that have previously paired with bluetooth biometric hardware, |
| 82 | + /// but are not currently paired to it. |
| 83 | + /// |
| 84 | + /// Devices that could have removable hardware attached may return either this |
| 85 | + /// or [noBiometricHardware] depending on the platform implementation. |
| 86 | + /// Platforms should generally only return this code if the system provides |
| 87 | + /// information indicating that the device has previously had such hardware. |
| 88 | + biometricHardwareTemporarilyUnavailable, |
| 89 | + |
| 90 | + /// Authentication has temporarily been locked out, and should be re-attempted |
| 91 | + /// later. |
| 92 | + /// |
| 93 | + /// For example, devices may return this error after too many failed |
| 94 | + /// authentication attempts. |
| 95 | + temporaryLockout, |
| 96 | + |
| 97 | + /// Biometric authentication has been locked until some other authentication |
| 98 | + /// has succeeded. |
| 99 | + /// |
| 100 | + /// Applications that do not require biometric authentication should generally |
| 101 | + /// handle this error by re-attempting authentication with fallback to |
| 102 | + /// non-biometrics allowed. Applications that require biometrics should |
| 103 | + /// prompt users to resolve the lockout. |
| 104 | + biometricLockout, |
| 105 | + |
| 106 | + /// The user indicated via system-provided UI that they want to use a fallback |
| 107 | + /// authentication option instead of biometrics. |
| 108 | + /// |
| 109 | + /// Whether this can be returned depends on the platform implementation and |
| 110 | + /// the authentication configuration options. Applications should generally |
| 111 | + /// handle this error by offering the user an alternate authentication option. |
| 112 | + userRequestedFallback, |
| 113 | + |
| 114 | + /// The authentication attempt failed due to some device-level error. |
| 115 | + /// |
| 116 | + /// The [LocalAuthException.description] should contain more details about the |
| 117 | + /// error. |
| 118 | + deviceError, |
| 119 | + |
| 120 | + /// The authentication attempt failed due to some unknown or unexpected error. |
| 121 | + /// |
| 122 | + /// The [LocalAuthException.description] should contain more details about the |
| 123 | + /// error. |
| 124 | + unknownError, |
| 125 | +} |
0 commit comments