forked from firebase/flutterfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.dart
81 lines (70 loc) 路 2.08 KB
/
provider.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
import 'package:firebase_auth/firebase_auth.dart' hide OAuthProvider;
import 'package:flutter/foundation.dart';
import 'package:firebase_ui_oauth/firebase_ui_oauth.dart';
import 'package:firebase_ui_oauth_google/firebase_ui_oauth_google.dart';
import 'package:google_sign_in/google_sign_in.dart';
class GoogleProvider extends OAuthProvider {
@override
final providerId = 'google.com';
final String clientId;
final String? redirectUri;
final List<String>? scopes;
late GoogleSignIn provider = GoogleSignIn(
scopes: scopes ?? [],
clientId: clientId,
);
@override
final GoogleAuthProvider firebaseAuthProvider = GoogleAuthProvider();
@override
late final desktopSignInArgs = GoogleSignInArgs(
clientId: clientId,
redirectUri: redirectUri ?? defaultRedirectUri,
scope: scopes != null
? scopes!.join(' ')
: 'https://www.googleapis.com/auth/plus.login',
);
GoogleProvider({
required this.clientId,
this.redirectUri,
this.scopes,
}) {
firebaseAuthProvider.setCustomParameters(const {
'prompt': 'select_account',
});
}
@override
void mobileSignIn(AuthAction action) async {
provider.signIn().then((user) {
if (user == null) throw AuthCancelledException();
return user.authentication;
}).then((auth) {
final credential = GoogleAuthProvider.credential(
accessToken: auth.accessToken,
idToken: auth.idToken,
);
onCredentialReceived(credential, action);
}).catchError((err) {
authListener.onError(err);
});
}
@override
OAuthCredential fromDesktopAuthResult(AuthResult result) {
return GoogleAuthProvider.credential(
idToken: result.idToken,
accessToken: result.accessToken,
);
}
@override
Future<void> logOutProvider() async {
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
await provider.signOut();
}
}
@override
final style = const GoogleProviderButtonStyle();
@override
bool supportsPlatform(TargetPlatform platform) {
return true;
}
}