-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
firebase_app_check.dart
85 lines (71 loc) 路 3.21 KB
/
firebase_app_check.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
// ignore_for_file: require_trailing_commas
// Copyright 2021 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.
part of firebase_app_check;
class FirebaseAppCheck extends FirebasePluginPlatform {
static Map<String, FirebaseAppCheck> _firebaseAppCheckInstances = {};
FirebaseAppCheck._({required this.app})
: super(app.name, 'plugins.flutter.io/firebase_app_check');
/// Cached instance of [FirebaseAppCheck];
static FirebaseAppCheck? _instance;
/// The [FirebaseApp] for this current [FirebaseAppCheck] instance.
FirebaseApp app;
// Cached and lazily loaded instance of [FirebaseAppCheckPlatform] to avoid
// creating a [MethodChannelFirebaseAppCheck] when not needed or creating an
// instance with the default app before a user specifies an app.
FirebaseAppCheckPlatform? _delegatePackingProperty;
/// Returns the underlying delegate implementation.
///
/// If called and no [_delegatePackingProperty] exists, it will first be
/// created and assigned before returning the delegate.
FirebaseAppCheckPlatform get _delegate {
_delegatePackingProperty ??= FirebaseAppCheckPlatform.instanceFor(
app: app,
);
return _delegatePackingProperty!;
}
/// Returns an instance using the default [FirebaseApp].
static FirebaseAppCheck get instance {
_instance ??= FirebaseAppCheck._(app: Firebase.app());
return _instance!;
}
/// Returns an instance using a specified [FirebaseApp].
static FirebaseAppCheck instanceFor({required FirebaseApp app}) {
return _firebaseAppCheckInstances.putIfAbsent(app.name, () {
return FirebaseAppCheck._(app: app);
});
}
/// Activates the Firebase App Check service.
///
/// On web, provide the reCAPTCHA v3 Site Key which can be found in the
/// Firebase Console. For more information, see
/// [the Firebase Documentation](https://firebase.google.com/docs/app-check/web).
///
/// On Android, you may set androidDebugProvider to "true" to use the debug provider
/// For more information, see [the Firebase Documentation](https://firebase.google.com/docs/app-check/android/debug-provider)
Future<void> activate(
{String? webRecaptchaSiteKey, bool? androidDebugProvider = false}) {
return _delegate.activate(
webRecaptchaSiteKey: webRecaptchaSiteKey,
androidDebugProvider: androidDebugProvider);
}
/// Get the current App Check token.
///
/// Attaches to the most recent in-flight request if one is present. Returns
/// null if no token is present and no token requests are in-flight.
///
/// If `forceRefresh` is true, will always try to fetch a fresh token. If
/// false, will use a cached token if found in storage.
Future<String?> getToken([bool? forceRefresh]) async {
return _delegate.getToken(forceRefresh ?? false);
}
/// If true, the SDK automatically refreshes App Check tokens as needed.
Future<void> setTokenAutoRefreshEnabled(bool isTokenAutoRefreshEnabled) {
return _delegate.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled);
}
/// Registers a listener to changes in the token state.
Stream<String?> get onTokenChange {
return _delegate.onTokenChange;
}
}