Skip to content
This repository was archived by the owner on Feb 21, 2021. It is now read-only.

Commit 858f42a

Browse files
authored
Add Google auth scope. (#4)
1 parent 50514cd commit 858f42a

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 0.2.1
2+
3+
- Add an option to add additional authorization scopes to `googleSignIn`:
4+
5+
```dart
6+
// Authenticate and allow read-only access to Google Calendar.
7+
final user = await firebaseAuth.googleSignIn(
8+
scopes: [
9+
'https://www.googleapis.com/auth/calendar.readonly',
10+
],
11+
);
12+
13+
if (user != null) {
14+
// You have access!
15+
}
16+
```
17+
118
## 0.2.0
219

320
- Fixed a bug that flashed signed off content before loading.

lib/src/directives/firebase_auth.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ abstract class FirebaseAuth {
3535
/// Returns a future that completes after authenticated.
3636
///
3737
/// May optionally disable [prompt] if the user is already authenticated.
38-
Future<FirebaseUser> googleSignIn({bool prompt: true});
38+
Future<FirebaseUser> googleSignIn({
39+
bool prompt: true,
40+
List<String> scopes: const [],
41+
});
3942

4043
/// Sign out of any authenticated account.
4144
Future<Null> signOut();
4245
}
4346

4447
class _SdkFirebaseAuth implements FirebaseAuth {
45-
static final _googleAuth = new sdk.GoogleAuthProvider();
46-
4748
final sdk.App _app;
4849
final _onUserChanged = new StreamController<FirebaseUser>.broadcast();
4950

@@ -70,12 +71,15 @@ class _SdkFirebaseAuth implements FirebaseAuth {
7071
@override
7172
Future<FirebaseUser> googleSignIn({
7273
bool prompt: true,
74+
List<String> scopes: const [],
7375
}) async {
74-
_googleAuth.setCustomParameters(<String, String>{
76+
final googleAuth = new sdk.GoogleAuthProvider();
77+
scopes.forEach(googleAuth.addScope);
78+
googleAuth.setCustomParameters(<String, dynamic>{
7579
'prompt': prompt ? 'select_account' : 'none',
7680
});
7781
try {
78-
final user = await _app.auth().signInWithPopup(_googleAuth);
82+
final user = await _app.auth().signInWithPopup(googleAuth);
7983
return new FirebaseUser._fromSdk(user.user);
8084
} catch (_) {
8185
return null;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: angular_fire
22
description: >
33
Unofficial library for AngularDart and Firebase.
4-
version: 0.2.0
4+
version: 0.2.1
55
authors:
66
- Matan Lurey <matanl@google.com>
77
homepage: https://github.com/matanlurey/angular_fire

web/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class AngularFireExample {
5959
AngularFireExample(this._auth);
6060

6161
void signIn() {
62-
_auth.googleSignIn();
62+
_auth.googleSignIn(scopes: [
63+
'https://www.googleapis.com/auth/calendar.readonly',
64+
]);
6365
}
6466

6567
void signOut() {

0 commit comments

Comments
 (0)