-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
platform_interface_multi_factor.dart
182 lines (151 loc) 路 6.46 KB
/
platform_interface_multi_factor.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';
import 'package:firebase_auth_platform_interface/src/method_channel/method_channel_multi_factor.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
/// {@template .platformInterfaceMultiFactor}
/// The platform defining the interface of multi-factor related
/// properties and operations pertaining to a [User].
/// {@endtemplate}
abstract class MultiFactorPlatform extends PlatformInterface {
/// {@macro .platformInterfaceMultiFactor}
MultiFactorPlatform(
this.auth,
) : super(token: _token);
/// The [FirebaseAuthPlatform] instance.
final FirebaseAuthPlatform auth;
static final Object _token = Object();
/// Enrolls a second factor as identified by the [MultiFactorAssertion] parameter for the current user.
///
/// [displayName] can be used to provide a display name for the second factor.
Future<void> enroll(
MultiFactorAssertionPlatform assertion, {
String? displayName,
}) {
throw UnimplementedError('enroll() is not implemented');
}
/// Returns a session identifier for a second factor enrollment operation.
Future<MultiFactorSession> getSession() {
throw UnimplementedError('getSession() is not implemented');
}
/// Unenrolls a second factor from this user.
///
/// [factorUid] is the unique identifier of the second factor to unenroll.
/// [multiFactorInfo] is the [MultiFactorInfo] of the second factor to unenroll.
/// Only one of [factorUid] or [multiFactorInfo] should be provided.
Future<void> unenroll({String? factorUid, MultiFactorInfo? multiFactorInfo}) {
throw UnimplementedError('unenroll() is not implemented');
}
/// Returns a list of the [MultiFactorInfo] already associated with this user.
Future<List<MultiFactorInfo>> getEnrolledFactors() {
throw UnimplementedError('getEnrolledFactors() is not implemented');
}
}
/// Identifies the current session to enroll a second factor or to complete sign in when previously enrolled.
///
/// It contains additional context on the existing user, notably the confirmation that the user passed the first factor challenge.
class MultiFactorSession {
MultiFactorSession(this.id);
final String id;
}
/// {@template .multiFactorAssertion}
/// Represents an assertion that the Firebase Authentication server
/// can use to authenticate a user as part of a multi-factor flow.
/// {@endtemplate}
class MultiFactorAssertionPlatform extends PlatformInterface {
/// {@macro .multiFactorAssertion}
MultiFactorAssertionPlatform() : super(token: _token);
static final Object _token = Object();
/// Ensures that any delegate class has extended a [MultiFactorResolverPlatform].
static void verifyExtends(MultiFactorAssertionPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
}
}
/// {@template .platformInterfaceMultiFactorResolverPlatform}
/// Utility class that contains methods to resolve second factor
/// requirements on users that have opted into two-factor authentication.
/// {@endtemplate}
class MultiFactorResolverPlatform extends PlatformInterface {
/// {@macro .platformInterfaceMultiFactorResolverPlatform}
MultiFactorResolverPlatform(
this.hints,
this.session,
) : super(token: _token);
static final Object _token = Object();
/// Ensures that any delegate class has extended a [MultiFactorResolverPlatform].
static void verifyExtends(MultiFactorResolverPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
}
/// List of [MultiFactorInfo] which represents the available
/// second factors that can be used to complete the sign-in for the current session.
final List<MultiFactorInfo> hints;
/// A MultiFactorSession, an opaque session identifier for the current sign-in flow.
final MultiFactorSession session;
/// Completes sign in with a second factor using an MultiFactorAssertion which
/// confirms that the user has successfully completed the second factor challenge.
Future<UserCredentialPlatform> resolveSignIn(
MultiFactorAssertionPlatform assertion,
) {
throw UnimplementedError('resolveSignIn() is not implemented');
}
}
/// Represents a single second factor means for the user.
///
/// See direct subclasses for type-specific information.
class MultiFactorInfo {
const MultiFactorInfo({
required this.factorId,
required this.enrollmentTimestamp,
required this.displayName,
required this.uid,
});
/// User-given display name for this second factor.
final String? displayName;
/// The enrollment timestamp for this second factor in seconds since epoch (UTC midnight on January 1, 1970).
final double enrollmentTimestamp;
/// The factor id of this second factor.
final String factorId;
/// The unique identifier for this second factor.
final String uid;
}
/// Represents the information for a phone second factor.
class PhoneMultiFactorInfo extends MultiFactorInfo {
const PhoneMultiFactorInfo({
required String? displayName,
required double enrollmentTimestamp,
required String factorId,
required String uid,
required this.phoneNumber,
}) : super(
displayName: displayName,
enrollmentTimestamp: enrollmentTimestamp,
factorId: factorId,
uid: uid,
);
/// The phone number associated with this second factor verification method.
final String phoneNumber;
}
/// Helper class used to generate PhoneMultiFactorAssertions.
class PhoneMultiFactorGeneratorPlatform extends PlatformInterface {
static PhoneMultiFactorGeneratorPlatform? _instance;
static final Object _token = Object();
PhoneMultiFactorGeneratorPlatform() : super(token: _token);
/// The current default [PhoneMultiFactorGeneratorPlatform] instance.
///
/// It will always default to [MethodChannelPhoneMultiFactorGenerator]
/// if no other implementation was provided.
static PhoneMultiFactorGeneratorPlatform get instance {
_instance ??= MethodChannelPhoneMultiFactorGenerator();
return _instance!;
}
/// Sets the [PhoneMultiFactorGeneratorPlatform.instance]
static set instance(PhoneMultiFactorGeneratorPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Transforms a PhoneAuthCredential into a [MultiFactorAssertion]
/// which can be used to confirm ownership of a phone second factor.
MultiFactorAssertionPlatform getAssertion(
PhoneAuthCredential credential,
) {
throw UnimplementedError('getAssertion() is not implemented');
}
}