-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
platform_interface_user.dart
536 lines (497 loc) 路 25 KB
/
platform_interface_user.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// ignore_for_file: require_trailing_commas
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
/// A user account.
abstract class UserPlatform extends PlatformInterface {
// ignore: public_member_api_docs
UserPlatform(this.auth, this.multiFactor, Map<String, dynamic> user)
: _user = user,
super(token: _token);
static final Object _token = Object();
/// Ensures that any delegate class has extended a [UserPlatform].
static void verifyExtends(UserPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
}
/// The [FirebaseAuthPlatform] instance.
final FirebaseAuthPlatform auth;
final MultiFactorPlatform multiFactor;
final Map<String, dynamic> _user;
/// The users display name.
///
/// Will be `null` if signing in anonymously or via password authentication.
String? get displayName {
return _user['displayName'];
}
/// The users email address.
///
/// Will be `null` if signing in anonymously.
String? get email {
return _user['email'];
}
/// Returns whether the users email address has been verified.
///
/// To send a verification email, see [sendEmailVerification].
///
/// Once verified, call [reload] to ensure the latest user information is
/// retrieved from Firebase.
bool get emailVerified {
return _user['emailVerified'];
}
/// Returns whether the user is a anonymous.
bool get isAnonymous {
return _user['isAnonymous'];
}
/// Returns additional metadata about the user, such as their creation time.
UserMetadata get metadata {
return UserMetadata(
_user['metadata']['creationTime'], _user['metadata']['lastSignInTime']);
}
/// Returns the users phone number.
///
/// This property will be `null` if the user has not signed in or been has
/// their phone number linked.
String? get phoneNumber {
return _user['phoneNumber'];
}
/// Returns a photo URL for the user.
///
/// This property will be populated if the user has signed in or been linked
/// with a 3rd party OAuth provider (such as Google).
String? get photoURL {
return _user['photoURL'];
}
/// Returns a list of user information for each linked provider.
List<UserInfo> get providerData {
return List.from(_user['providerData'])
.map((data) => UserInfo(Map<String, String?>.from(data)))
.toList();
}
/// Returns a JWT refresh token for the user.
///
/// This property will be an empty string for native platforms (android, iOS & macOS) as they do not
/// support refresh tokens.
String? get refreshToken {
return _user['refreshToken'];
}
/// The current user's tenant ID.
///
/// This is a read-only property, which indicates the tenant ID used to sign
/// in the current user. This is `null` if the user is signed in from the
/// parent project.
String? get tenantId {
return _user['tenantId'];
}
/// The user's unique ID.
String get uid {
return _user['uid'];
}
/// Deletes and signs out the user.
///
/// **Important**: this is a security-sensitive operation that requires the
/// user to have recently signed in. If this requirement isn't met, ask the
/// user to authenticate again and then call [User.reauthenticateWithCredential].
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **requires-recent-login**:
/// - Thrown if the user's last sign-in time does not meet the security
/// threshold. Use [User.reauthenticateWithCredential] to resolve. This
/// does not apply if the user is anonymous.
Future<void> delete() async {
throw UnimplementedError('delete() is not implemented');
}
/// Returns a JSON Web Token (JWT) used to identify the user to a Firebase
/// service.
///
/// Returns the current token if it has not expired. Otherwise, this will
/// refresh the token and return a new one.
///
/// If [forceRefresh] is `true`, the token returned will be refresh regardless
/// of token expiration.
Future<String> getIdToken(bool forceRefresh) {
throw UnimplementedError('getIdToken() is not implemented');
}
/// Returns a [IdTokenResult] containing the users JSON Web Token (JWT) and
/// other metadata.
///
/// Returns the current token if it has not expired. Otherwise, this will
/// refresh the token and return a new one.
///
/// If [forceRefresh] is `true`, the token returned will be refresh regardless
/// of token expiration.
Future<IdTokenResult> getIdTokenResult(bool forceRefresh) {
throw UnimplementedError('getIdTokenResult() is not implemented');
}
/// Links the user account with the given credentials.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **provider-already-linked**:
/// - Thrown if the provider has already been linked to the user. This error
/// is thrown even if this is not the same provider's account that is
/// currently linked to the user.
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **credential-already-in-use**:
/// - Thrown if the account corresponding to the credential already exists
/// among your users, or is already linked to a Firebase User. For example,
/// this error could be thrown if you are upgrading an anonymous user to a
/// Google user by linking a Google credential to it and the Google
/// credential used is already associated with an existing Firebase Google
/// user. The fields `email`, `phoneNumber`, and `credential`
/// ([AuthCredential]) may be provided, depending on the type of
/// credential. You can recover from this error by signing in with
/// `credential` directly via [signInWithCredential].
/// - **email-already-in-use**:
/// - Thrown if the email corresponding to the credential already exists
/// among your users. When thrown while linking a credential to an existing
/// user, an `email` and `credential` ([AuthCredential]) fields are also
/// provided. You have to link the credential to the existing user with
/// that email if you wish to continue signing in with that credential.
/// To do so, call [fetchSignInMethodsForEmail], sign in to `email` via one
/// of the providers returned and then [User.linkWithCredential] the
/// original credential to that newly signed in user.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
/// - **invalid-verification-code**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification code of the credential is not valid.
/// - **invalid-verification-id**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification ID of the credential is not valid.
Future<UserCredentialPlatform> linkWithCredential(AuthCredential credential) {
throw UnimplementedError('linkWithCredential() is not implemented');
}
/// Signs in with an AuthProvider using native authentication flow.
/// On Web you should use [linkWithPopup] or [linkWithRedirect] instead.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **provider-already-linked**:
/// - Thrown if the provider has already been linked to the user. This error
/// is thrown even if this is not the same provider's account that is
/// currently linked to the user.
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **credential-already-in-use**:
/// - Thrown if the account corresponding to the credential already exists
/// among your users, or is already linked to a Firebase User. For example,
/// this error could be thrown if you are upgrading an anonymous user to a
/// Google user by linking a Google credential to it and the Google
/// credential used is already associated with an existing Firebase Google
/// user. The fields `email`, `phoneNumber`, and `credential`
/// ([AuthCredential]) may be provided, depending on the type of
/// credential. You can recover from this error by signing in with
/// `credential` directly via [signInWithCredential].
/// - **email-already-in-use**:
/// - Thrown if the email corresponding to the credential already exists
/// among your users. When thrown while linking a credential to an existing
/// user, an `email` and `credential` ([AuthCredential]) fields are also
/// provided. You have to link the credential to the existing user with
/// that email if you wish to continue signing in with that credential.
/// To do so, call [fetchSignInMethodsForEmail], sign in to `email` via one
/// of the providers returned and then [User.linkWithCredential] the
/// original credential to that newly signed in user.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
/// - **invalid-verification-code**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification code of the credential is not valid.
/// - **invalid-verification-id**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification ID of the credential is not valid.
Future<UserCredentialPlatform> linkWithProvider(AuthProvider provider) {
throw UnimplementedError('linkWithProvider() is not implemented');
}
/// Renews the user鈥檚 authentication using the provided auth provider instance.
/// On Web you should use [linkWithPopup] instead.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
Future<UserCredentialPlatform> reauthenticateWithProvider(
AuthProvider provider,
) {
throw UnimplementedError('reauthenticateWithProvider() is not implemented');
}
/// Renews the user鈥檚 authentication using the provided auth provider instance.
/// On mobile you should use [reauthenticateWithProvider] instead.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
Future<UserCredentialPlatform> reauthenticateWithPopup(
AuthProvider provider,
) {
throw UnimplementedError('reauthenticateWithPopup() is not implemented');
}
/// Renews the user鈥檚 authentication using the provided auth provider instance.
/// On mobile you should use [reauthenticateWithProvider] instead.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
Future<void> reauthenticateWithRedirect(
AuthProvider provider,
) {
throw UnimplementedError('reauthenticateWithRedirect() is not implemented');
}
/// Links the user account with the given provider.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **provider-already-linked**:
/// - Thrown if the provider has already been linked to the user. This error
/// is thrown even if this is not the same provider's account that is
/// currently linked to the user.
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **credential-already-in-use**:
/// - Thrown if the account corresponding to the credential already exists
/// among your users, or is already linked to a Firebase User. For example,
/// this error could be thrown if you are upgrading an anonymous user to a
/// Google user by linking a Google credential to it and the Google
/// credential used is already associated with an existing Firebase Google
/// user. The fields `email`, `phoneNumber`, and `credential`
/// ([AuthCredential]) may be provided, depending on the type of
/// credential. You can recover from this error by signing in with
/// `credential` directly via [signInWithCredential].
/// - **email-already-in-use**:
/// - Thrown if the email corresponding to the credential already exists
/// among your users. When thrown while linking a credential to an existing
/// user, an `email` and `credential` ([AuthCredential]) fields are also
/// provided. You have to link the credential to the existing user with
/// that email if you wish to continue signing in with that credential.
/// To do so, call [fetchSignInMethodsForEmail], sign in to `email` via one
/// of the providers returned and then [User.linkWithCredential] the
/// original credential to that newly signed in user.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
Future<UserCredentialPlatform> linkWithPopup(AuthProvider provider) {
throw UnimplementedError('linkWithPopup() is not implemented');
}
/// Links the user account with the given provider.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **provider-already-linked**:
/// - Thrown if the provider has already been linked to the user. This error
/// is thrown even if this is not the same provider's account that is
/// currently linked to the user.
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **credential-already-in-use**:
/// - Thrown if the account corresponding to the credential already exists
/// among your users, or is already linked to a Firebase User. For example,
/// this error could be thrown if you are upgrading an anonymous user to a
/// Google user by linking a Google credential to it and the Google
/// credential used is already associated with an existing Firebase Google
/// user. The fields `email`, `phoneNumber`, and `credential`
/// ([AuthCredential]) may be provided, depending on the type of
/// credential. You can recover from this error by signing in with
/// `credential` directly via [signInWithCredential].
/// - **email-already-in-use**:
/// - Thrown if the email corresponding to the credential already exists
/// among your users. When thrown while linking a credential to an existing
/// user, an `email` and `credential` ([AuthCredential]) fields are also
/// provided. You have to link the credential to the existing user with
/// that email if you wish to continue signing in with that credential.
/// To do so, call [fetchSignInMethodsForEmail], sign in to `email` via one
/// of the providers returned and then [User.linkWithCredential] the
/// original credential to that newly signed in user.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the provider in the Firebase Console. Go
/// to the Firebase Console for your project, in the Auth section and the
/// Sign in Method tab and configure the provider.
Future<void> linkWithRedirect(AuthProvider provider) {
throw UnimplementedError('linkWithRedirect() is not implemented');
}
/// Links the user account with the given phone number.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **provider-already-linked**:
/// - Thrown if the provider has already been linked to the user. This error
/// is thrown even if this is not the same provider's account that is
/// currently linked to the user.
/// - **captcha-check-failed**:
/// - Thrown if the reCAPTCHA response token was invalid, expired, or if this
/// method was called from a non-whitelisted domain.
/// - **invalid-phone-number**:
/// - Thrown if the phone number has an invalid format.
/// - **quota-exceeded**:
/// - Thrown if the SMS quota for the Firebase project has been exceeded.
/// - **user-disabled**:
/// - Thrown if the user corresponding to the given phone number has been disabled.
/// - **credential-already-in-use**:
/// - Thrown if the account corresponding to the phone number already exists
/// among your users, or is already linked to a Firebase User.
/// - **operation-not-allowed**:
/// - Thrown if you have not enabled the phone authentication provider in the
/// Firebase Console. Go to the Firebase Console for your project, in the Auth
/// section and the Sign in Method tab and configure the provider.
Future<ConfirmationResultPlatform> linkWithPhoneNumber(
String phoneNumber,
RecaptchaVerifierFactoryPlatform applicationVerifier,
) {
throw UnimplementedError('linkWithPhoneNumber() is not implemented');
}
/// Re-authenticates a user using a fresh credential.
///
/// Use before operations such as [User.updatePassword] that require tokens
/// from recent sign-in attempts.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **user-mismatch**:
/// - Thrown if the credential given does not correspond to the user.
/// - **user-not-found**:
/// - Thrown if the credential given does not correspond to any existing
/// user.
/// - **invalid-credential**:
/// - Thrown if the provider's credential is not valid. This can happen if it
/// has already expired when calling link, or if it used invalid token(s).
/// See the Firebase documentation for your provider, and make sure you
/// pass in the correct parameters to the credential method.
/// - **invalid-email**:
/// - Thrown if the email used in a [EmailAuthProvider.credential] is
/// invalid.
/// - **wrong-password**:
/// - Thrown if the password used in a [EmailAuthProvider.credential] is not
/// correct or when the user associated with the email does not have a
/// password.
/// - **invalid-verification-code**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification code of the credential is not valid.
/// - **invalid-verification-id**:
/// - Thrown if the credential is a [PhoneAuthProvider.credential] and the
/// verification ID of the credential is not valid.
Future<UserCredentialPlatform> reauthenticateWithCredential(
AuthCredential credential) {
throw UnimplementedError(
'reauthenticateWithCredential() is not implemented');
}
/// Refreshes the current user, if signed in.
Future<void> reload() async {
throw UnimplementedError('reload() is not implemented');
}
/// Sends a verification email to a user.
///
/// The verification process is completed by calling [applyActionCode].
Future<void> sendEmailVerification(
ActionCodeSettings? actionCodeSettings,
) async {
throw UnimplementedError('sendEmailVerification() is not implemented');
}
/// Unlinks a provider from a user account.
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **no-such-provider**:
/// - Thrown if the user does not have this provider linked or when the
/// provider ID given does not exist.
Future<UserPlatform> unlink(String providerId) async {
throw UnimplementedError('unlink() is not implemented');
}
/// Updates the user's email address.
///
/// An email will be sent to the original email address (if it was set) that
/// allows to revoke the email address change, in order to protect them from
/// account hijacking.
///
/// **Important**: this is a security sensitive operation that requires the
/// user to have recently signed in. If this requirement isn't met, ask the
/// user to authenticate again and then call [User.reauthenticateWithCredential].
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **invalid-email**:
/// - Thrown if the email used is invalid.
/// - **email-already-in-use**:
/// - Thrown if the email is already used by another user.
/// - **requires-recent-login**:
/// - Thrown if the user's last sign-in time does not meet the security
/// threshold. Use [User.reauthenticateWithCredential] to resolve. This
/// does not apply if the user is anonymous.
Future<void> updateEmail(String newEmail) async {
throw UnimplementedError('updateEmail() is not implemented');
}
/// Updates the user's password.
///
/// **Important**: this is a security sensitive operation that requires the
/// user to have recently signed in. If this requirement isn't met, ask the
/// user to authenticate again and then call [User.reauthenticateWithCredential].
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **weak-password**:
/// - Thrown if the password is not strong enough.
/// - **requires-recent-login**:
/// - Thrown if the user's last sign-in time does not meet the security
/// threshold. Use [User.reauthenticateWithCredential] to resolve. This
/// does not apply if the user is anonymous.
Future<void> updatePassword(String newPassword) async {
throw UnimplementedError('updatePassword() is not implemented');
}
/// Updates the user's phone number.
///
/// A credential can be created by verifying a phone number via
/// [verifyPhoneNumber].
///
/// A [FirebaseAuthException] maybe thrown with the following error code:
/// - **invalid-verification-code**:
/// - Thrown if the verification code of the credential is not valid.
/// - **invalid-verification-id**:
/// - Thrown if the verification ID of the credential is not valid.
Future<void> updatePhoneNumber(PhoneAuthCredential phoneCredential) async {
throw UnimplementedError('updatePhoneNumber() is not implemented');
}
/// Updates a user's profile data.
Future<void> updateProfile(Map<String, String?> profile) async {
throw UnimplementedError('updateProfile() is not implemented');
}
/// Sends a verification email to a new email address. The user's email will
/// be updated to the new one after being verified.
///
/// If you have a custom email action handler, you can complete the
/// verification process by calling [applyActionCode].
Future<void> verifyBeforeUpdateEmail(
String newEmail, [
ActionCodeSettings? actionCodeSettings,
]) async {
throw UnimplementedError('verifyBeforeUpdateEmail() is not implemented');
}
}