Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit f198ee4

Browse files
Janamoukevmoo
authored andcommitted
New release (#104)
* Latest firebase update * Updates in auth * Support for storage buckets * AuthCredential provider deprecated * Deprecated message
1 parent 685c6d8 commit f198ee4

17 files changed

+141
-25
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 3.1.0
2+
3+
* Updates from the Firebase `3.8.0` and `3.9.0` in `auth` library:
4+
* `User`
5+
* Deprecated `link` method in favor of `linkWithCredential`.
6+
* Deprecated `reauthenticate` method in favor of `reauthenticateWithCredential`.
7+
* Added new `reauthenticateWithPopup` and `reauthenticateWithRedirect` methods.
8+
* `UserCredential`
9+
* Added new `operationType` property.
10+
* `AuthCredential`
11+
* Deprecated `provider` property in favor of `providerId`.
12+
* The `app.storage()` has now an optional storage bucket parameter.
13+
114
## 3.0.2
215

316
* Throw `FirebaseClientException` if there are request failures in

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You must include the original Firebase JavaScript source into your `.html` file
3636
to be able to use the library.
3737

3838
```html
39-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
39+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
4040
```
4141

4242
### Use it

example/auth/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h2 id="auth_info" style="display: none">
2525
</h2>
2626
<a href="#" id="logout_btn" style="display: none">Log out</a>
2727
</div>
28-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
28+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
2929
<script src="index.dart" type="application/dart"></script>
3030
<script src="packages/browser/dart.js"></script>
3131
</body>

example/realtime_database/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h1>Messages demo</h1>
4646
<input type="submit" value="Send" id="submit" disabled>
4747
</form>
4848
</div>
49-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
49+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
5050
<script src="index.dart" type="application/dart"></script>
5151
<script src="packages/browser/dart.js"></script>
5252
</body>

example/storage/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1>Upload image demo</h1>
1414
</form>
1515
<p id="message"></p>
1616
</div>
17-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
17+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
1818
<script src="index.dart" type="application/dart"></script>
1919
<script src="packages/browser/dart.js"></script>
2020
</body>

lib/src/app.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class App extends JsObjectWrapper<AppJsImpl> {
3333
/// Deletes the app and frees resources of all App's services.
3434
Future delete() => handleThenable(jsObject.delete());
3535

36-
/// Returns [Storage] service.
37-
Storage storage() => new Storage.fromJsObject(jsObject.storage());
36+
/// Returns [Storage] service optionally initialized with a custom storage bucket.
37+
Storage storage([String url]) {
38+
var jsObjectStorage =
39+
(url != null) ? jsObject.storage(url) : jsObject.storage();
40+
return new Storage.fromJsObject(jsObjectStorage);
41+
}
3842
}

lib/src/auth.dart

+45-7
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ class User extends UserInfo<firebase_interop.UserJsImpl> {
8383
Future<String> getToken([bool forceRefresh = false]) =>
8484
handleThenable(jsObject.getToken(forceRefresh));
8585

86-
/// Links the user account with the given [credential] and returns the user.
86+
/// _Deprecated: Use [linkWithCredential] instead._
87+
@deprecated
8788
Future<User> link(AuthCredential credential) => handleThenableWithMapper(
8889
jsObject.link(credential), (u) => new User.fromJsObject(u));
8990

91+
/// Links the user account with the given [credential] and returns the user.
92+
Future<User> linkWithCredential(AuthCredential credential) =>
93+
handleThenableWithMapper(jsObject.linkWithCredential(credential),
94+
(u) => new User.fromJsObject(u));
95+
9096
/// Links the authenticated [provider] to the user account using
9197
/// a pop-up based OAuth flow.
9298
/// It returns the [UserCredential] information if linking is successful.
@@ -99,11 +105,29 @@ class User extends UserInfo<firebase_interop.UserJsImpl> {
99105
Future linkWithRedirect(AuthProvider provider) =>
100106
handleThenable(jsObject.linkWithRedirect(provider.jsObject));
101107

108+
/// _Deprecated: Use [reauthenticateWithCredential] instead._
109+
@deprecated
110+
Future reauthenticate(AuthCredential credential) =>
111+
handleThenable(jsObject.reauthenticate(credential));
112+
102113
/// Re-authenticates a user using a fresh [credential]. Should be used
103114
/// before operations such as [updatePassword()] that require tokens
104115
/// from recent sign in attempts.
105-
Future reauthenticate(AuthCredential credential) =>
106-
handleThenable(jsObject.reauthenticate(credential));
116+
Future reauthenticateWithCredential(AuthCredential credential) =>
117+
handleThenable(jsObject.reauthenticateWithCredential(credential));
118+
119+
/// Reauthenticates a user with the specified provider using
120+
/// a pop-up based OAuth flow.
121+
/// It returns the [UserCredential] information if reauthentication is successful.
122+
Future<UserCredential> reauthenticateWithPopup(AuthProvider provider) =>
123+
handleThenableWithMapper(
124+
jsObject.reauthenticateWithPopup(provider.jsObject),
125+
(u) => new UserCredential.fromJsObject(u));
126+
127+
/// Reauthenticates a user with the specified OAuth [provider] using
128+
/// a full-page redirect flow.
129+
Future reauthenticateWithRedirect(AuthProvider provider) =>
130+
handleThenable(jsObject.reauthenticateWithRedirect(provider.jsObject));
107131

108132
/// If signed in, it refreshes the current user.
109133
Future reload() => handleThenable(jsObject.reload());
@@ -468,7 +492,9 @@ class AuthEvent {
468492
AuthEvent(this.user);
469493
}
470494

471-
/// A structure containing [User] and [AuthCredential].
495+
/// A structure containing a [User], an [AuthCredential] and [operationType].
496+
/// operationType could be 'signIn' for a sign-in operation, 'link' for a
497+
/// linking operation and 'reauthenticate' for a reauthentication operation.
472498
class UserCredential extends JsObjectWrapper<UserCredentialJsImpl> {
473499
User _user;
474500

@@ -500,10 +526,22 @@ class UserCredential extends JsObjectWrapper<UserCredentialJsImpl> {
500526
jsObject.credential = c;
501527
}
502528

503-
/// Creates a new UserCredential with optional [user] and [credential].
504-
factory UserCredential({User user, AuthCredential credential}) =>
529+
/// Returns the operation type.
530+
String get operationType => jsObject.operationType;
531+
532+
/// Sets the operation type to [t].
533+
void set operationType(String t) {
534+
jsObject.operationType = t;
535+
}
536+
537+
/// Creates a new UserCredential with optional [user], [credential]
538+
/// and [operationType].
539+
factory UserCredential(
540+
{User user, AuthCredential credential, String operationType}) =>
505541
new UserCredential.fromJsObject(new UserCredentialJsImpl(
506-
user: user.jsObject, credential: credential));
542+
user: user.jsObject,
543+
credential: credential,
544+
operationType: operationType));
507545

508546
/// Creates a new UserCredential from a [jsObject].
509547
UserCredential.fromJsObject(UserCredentialJsImpl jsObject)

lib/src/interop/app_interop.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ abstract class AppJsImpl {
1515
external AuthJsImpl auth();
1616
external DatabaseJsImpl database();
1717
external PromiseJsImpl delete();
18-
external StorageJsImpl storage();
18+
external StorageJsImpl storage([String url]);
1919
}

lib/src/interop/auth_interop.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ abstract class AuthJsImpl {
4343
/// See: <https://firebase.google.com/docs/reference/js/firebase.auth.AuthCredential>.
4444
@JS()
4545
abstract class AuthCredential {
46+
/// _Deprecated: Use [providerId] instead._
47+
@deprecated
4648
external String get provider;
49+
50+
/// The authentication provider ID for the credential.
51+
external String get providerId;
4752
external String get accessToken;
4853
external String get secret;
4954
}
@@ -129,7 +134,9 @@ class UserCredentialJsImpl {
129134
external void set user(UserJsImpl u);
130135
external AuthCredential get credential;
131136
external void set credential(AuthCredential c);
137+
external String get operationType;
138+
external void set operationType(String t);
132139

133140
external factory UserCredentialJsImpl(
134-
{UserJsImpl user, AuthCredential credential});
141+
{UserJsImpl user, AuthCredential credential, String operationType});
135142
}

lib/src/interop/firebase_interop.dart

+8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ abstract class UserJsImpl extends UserInfoJsImpl {
3535
external PromiseJsImpl delete();
3636
external PromiseJsImpl<String> getToken([bool opt_forceRefresh]);
3737
external PromiseJsImpl<UserJsImpl> link(AuthCredential credential);
38+
external PromiseJsImpl<UserJsImpl> linkWithCredential(
39+
AuthCredential credential);
3840
external PromiseJsImpl<UserCredentialJsImpl> linkWithPopup(
3941
AuthProviderJsImpl provider);
4042
external PromiseJsImpl linkWithRedirect(AuthProviderJsImpl provider);
4143
external PromiseJsImpl reauthenticate(AuthCredential credential);
44+
external PromiseJsImpl reauthenticateWithCredential(
45+
AuthCredential credential);
46+
external PromiseJsImpl<UserCredentialJsImpl> reauthenticateWithPopup(
47+
AuthProviderJsImpl provider);
48+
external PromiseJsImpl reauthenticateWithRedirect(
49+
AuthProviderJsImpl provider);
4250
external PromiseJsImpl reload();
4351
external PromiseJsImpl sendEmailVerification();
4452
external PromiseJsImpl<UserJsImpl> unlink(String providerId);

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: firebase
22
description: Dart libraries for Firebase
3-
version: 3.0.2
3+
version: 3.1.0
44
authors:
55
- Jana Moudra <[email protected]>
66
- Kevin Moore <[email protected]>

test/app_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ void main() {
4949
test("Get storage", () {
5050
expect(app.storage(), isNotNull);
5151
});
52+
53+
test("Get storage with a bucket", () {
54+
expect(app.storage("gs://$storageBucket"), isNotNull);
55+
});
5256
});
5357

5458
test("Can be created with name", () {

test/app_test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>App Test</title>
55
</head>
66
<body>
7-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
88
<script src="packages/test/dart.js"></script>
99
<link rel="x-dart-test" href="app_test.dart">
1010
</body>

test/auth_test.dart

+47-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
});
3838
test('credential', () {
3939
var cred = EmailAuthProvider.credential('un', 'pw');
40-
expect(cred.provider, equals(EmailAuthProvider.PROVIDER_ID));
40+
expect(cred.providerId, equals(EmailAuthProvider.PROVIDER_ID));
4141
});
4242
});
4343

@@ -51,7 +51,7 @@ void main() {
5151
});
5252
test('credential', () {
5353
var cred = FacebookAuthProvider.credential('token');
54-
expect(cred.provider, equals(FacebookAuthProvider.PROVIDER_ID));
54+
expect(cred.providerId, equals(FacebookAuthProvider.PROVIDER_ID));
5555
});
5656
test('scope', () {
5757
var provider = new FacebookAuthProvider();
@@ -76,7 +76,7 @@ void main() {
7676
});
7777
test('credential', () {
7878
var cred = GithubAuthProvider.credential('token');
79-
expect(cred.provider, equals(GithubAuthProvider.PROVIDER_ID));
79+
expect(cred.providerId, equals(GithubAuthProvider.PROVIDER_ID));
8080
});
8181
test('scope', () {
8282
var provider = new GithubAuthProvider();
@@ -101,7 +101,7 @@ void main() {
101101
});
102102
test('credential', () {
103103
var cred = GoogleAuthProvider.credential('idToken', 'accessToken');
104-
expect(cred.provider, equals(GoogleAuthProvider.PROVIDER_ID));
104+
expect(cred.providerId, equals(GoogleAuthProvider.PROVIDER_ID));
105105
});
106106
test('scope', () {
107107
var provider = new GoogleAuthProvider();
@@ -127,7 +127,7 @@ void main() {
127127
});
128128
test('credential', () {
129129
var cred = TwitterAuthProvider.credential('token', 'secret');
130-
expect(cred.provider, equals(TwitterAuthProvider.PROVIDER_ID));
130+
expect(cred.providerId, equals(TwitterAuthProvider.PROVIDER_ID));
131131
});
132132
test('custom parameters', () {
133133
var provider = new TwitterAuthProvider();
@@ -210,6 +210,48 @@ void main() {
210210
rethrow;
211211
}
212212
});
213+
214+
test('link anonymous user with credential', () async {
215+
try {
216+
user = await authValue.signInAnonymously();
217+
expect(user.isAnonymous, isTrue);
218+
219+
var credential =
220+
EmailAuthProvider.credential("[email protected]", "janicka");
221+
user = await user.linkWithCredential(credential);
222+
expect(user.isAnonymous, isFalse);
223+
expect(user.email, "[email protected]");
224+
} on FirebaseError catch (e) {
225+
printException(e);
226+
rethrow;
227+
}
228+
});
229+
230+
test('reauthenticate with credential', () async {
231+
try {
232+
user = await authValue.createUserWithEmailAndPassword(
233+
"[email protected]", "janicka");
234+
235+
var credential =
236+
EmailAuthProvider.credential("[email protected]", "janicka");
237+
await user.reauthenticateWithCredential(credential);
238+
239+
expect(authValue.currentUser, isNotNull);
240+
expect(authValue.currentUser.email, "[email protected]");
241+
} on FirebaseError catch (e) {
242+
printException(e);
243+
rethrow;
244+
}
245+
});
246+
247+
test('reauthenticate with bad credential fails', () async {
248+
user = await authValue.createUserWithEmailAndPassword(
249+
"[email protected]", "janicka");
250+
var credential =
251+
EmailAuthProvider.credential("[email protected]", "something");
252+
253+
expect(user.reauthenticateWithCredential(credential), throws);
254+
});
213255
});
214256

215257
group('registered user', () {

test/auth_test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Authentication Test</title>
55
</head>
66
<body>
7-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
88
<script src="packages/test/dart.js"></script>
99
<link rel="x-dart-test" href="auth_test.dart">
1010
</body>

test/database_test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Database Test</title>
55
</head>
66
<body>
7-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
88
<script src="packages/test/dart.js"></script>
99
<link rel="x-dart-test" href="database_test.dart">
1010
</body>

test/storage_test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Storage Test</title>
55
</head>
66
<body>
7-
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
88
<script src="packages/test/dart.js"></script>
99
<link rel="x-dart-test" href="storage_test.dart">
1010
</body>

0 commit comments

Comments
 (0)