diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ed868f..e6aea755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## 3.1.0 + +* Updates from the Firebase `3.8.0` and `3.9.0` in `auth` library: + * `User` + * Deprecated `link` method in favor of `linkWithCredential`. + * Deprecated `reauthenticate` method in favor of `reauthenticateWithCredential`. + * Added new `reauthenticateWithPopup` and `reauthenticateWithRedirect` methods. + * `UserCredential` + * Added new `operationType` property. + * `AuthCredential` + * Deprecated `provider` property in favor of `providerId`. +* The `app.storage()` has now an optional storage bucket parameter. + ## 3.0.2 * Throw `FirebaseClientException` if there are request failures in diff --git a/README.md b/README.md index 06455688..5b5ed706 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ You must include the original Firebase JavaScript source into your `.html` file to be able to use the library. ```html - + ``` ### Use it diff --git a/example/auth/index.html b/example/auth/index.html index 565d812b..046caaef 100644 --- a/example/auth/index.html +++ b/example/auth/index.html @@ -25,7 +25,7 @@ - + diff --git a/example/realtime_database/index.html b/example/realtime_database/index.html index a7aeae37..37935ba8 100644 --- a/example/realtime_database/index.html +++ b/example/realtime_database/index.html @@ -46,7 +46,7 @@

Messages demo

- + diff --git a/example/storage/index.html b/example/storage/index.html index d55fb915..b9a3fd65 100644 --- a/example/storage/index.html +++ b/example/storage/index.html @@ -14,7 +14,7 @@

Upload image demo

- + diff --git a/lib/src/app.dart b/lib/src/app.dart index 7c85127a..def2c133 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -33,6 +33,10 @@ class App extends JsObjectWrapper { /// Deletes the app and frees resources of all App's services. Future delete() => handleThenable(jsObject.delete()); - /// Returns [Storage] service. - Storage storage() => new Storage.fromJsObject(jsObject.storage()); + /// Returns [Storage] service optionally initialized with a custom storage bucket. + Storage storage([String url]) { + var jsObjectStorage = + (url != null) ? jsObject.storage(url) : jsObject.storage(); + return new Storage.fromJsObject(jsObjectStorage); + } } diff --git a/lib/src/auth.dart b/lib/src/auth.dart index 93c64f85..da5209d4 100644 --- a/lib/src/auth.dart +++ b/lib/src/auth.dart @@ -83,10 +83,16 @@ class User extends UserInfo { Future getToken([bool forceRefresh = false]) => handleThenable(jsObject.getToken(forceRefresh)); - /// Links the user account with the given [credential] and returns the user. + /// _Deprecated: Use [linkWithCredential] instead._ + @deprecated Future link(AuthCredential credential) => handleThenableWithMapper( jsObject.link(credential), (u) => new User.fromJsObject(u)); + /// Links the user account with the given [credential] and returns the user. + Future linkWithCredential(AuthCredential credential) => + handleThenableWithMapper(jsObject.linkWithCredential(credential), + (u) => new User.fromJsObject(u)); + /// Links the authenticated [provider] to the user account using /// a pop-up based OAuth flow. /// It returns the [UserCredential] information if linking is successful. @@ -99,11 +105,29 @@ class User extends UserInfo { Future linkWithRedirect(AuthProvider provider) => handleThenable(jsObject.linkWithRedirect(provider.jsObject)); + /// _Deprecated: Use [reauthenticateWithCredential] instead._ + @deprecated + Future reauthenticate(AuthCredential credential) => + handleThenable(jsObject.reauthenticate(credential)); + /// Re-authenticates a user using a fresh [credential]. Should be used /// before operations such as [updatePassword()] that require tokens /// from recent sign in attempts. - Future reauthenticate(AuthCredential credential) => - handleThenable(jsObject.reauthenticate(credential)); + Future reauthenticateWithCredential(AuthCredential credential) => + handleThenable(jsObject.reauthenticateWithCredential(credential)); + + /// Reauthenticates a user with the specified provider using + /// a pop-up based OAuth flow. + /// It returns the [UserCredential] information if reauthentication is successful. + Future reauthenticateWithPopup(AuthProvider provider) => + handleThenableWithMapper( + jsObject.reauthenticateWithPopup(provider.jsObject), + (u) => new UserCredential.fromJsObject(u)); + + /// Reauthenticates a user with the specified OAuth [provider] using + /// a full-page redirect flow. + Future reauthenticateWithRedirect(AuthProvider provider) => + handleThenable(jsObject.reauthenticateWithRedirect(provider.jsObject)); /// If signed in, it refreshes the current user. Future reload() => handleThenable(jsObject.reload()); @@ -468,7 +492,9 @@ class AuthEvent { AuthEvent(this.user); } -/// A structure containing [User] and [AuthCredential]. +/// A structure containing a [User], an [AuthCredential] and [operationType]. +/// operationType could be 'signIn' for a sign-in operation, 'link' for a +/// linking operation and 'reauthenticate' for a reauthentication operation. class UserCredential extends JsObjectWrapper { User _user; @@ -500,10 +526,22 @@ class UserCredential extends JsObjectWrapper { jsObject.credential = c; } - /// Creates a new UserCredential with optional [user] and [credential]. - factory UserCredential({User user, AuthCredential credential}) => + /// Returns the operation type. + String get operationType => jsObject.operationType; + + /// Sets the operation type to [t]. + void set operationType(String t) { + jsObject.operationType = t; + } + + /// Creates a new UserCredential with optional [user], [credential] + /// and [operationType]. + factory UserCredential( + {User user, AuthCredential credential, String operationType}) => new UserCredential.fromJsObject(new UserCredentialJsImpl( - user: user.jsObject, credential: credential)); + user: user.jsObject, + credential: credential, + operationType: operationType)); /// Creates a new UserCredential from a [jsObject]. UserCredential.fromJsObject(UserCredentialJsImpl jsObject) diff --git a/lib/src/interop/app_interop.dart b/lib/src/interop/app_interop.dart index b16f8345..dd678b40 100644 --- a/lib/src/interop/app_interop.dart +++ b/lib/src/interop/app_interop.dart @@ -15,5 +15,5 @@ abstract class AppJsImpl { external AuthJsImpl auth(); external DatabaseJsImpl database(); external PromiseJsImpl delete(); - external StorageJsImpl storage(); + external StorageJsImpl storage([String url]); } diff --git a/lib/src/interop/auth_interop.dart b/lib/src/interop/auth_interop.dart index 1e7a7669..745309c9 100644 --- a/lib/src/interop/auth_interop.dart +++ b/lib/src/interop/auth_interop.dart @@ -43,7 +43,12 @@ abstract class AuthJsImpl { /// See: . @JS() abstract class AuthCredential { + /// _Deprecated: Use [providerId] instead._ + @deprecated external String get provider; + + /// The authentication provider ID for the credential. + external String get providerId; external String get accessToken; external String get secret; } @@ -129,7 +134,9 @@ class UserCredentialJsImpl { external void set user(UserJsImpl u); external AuthCredential get credential; external void set credential(AuthCredential c); + external String get operationType; + external void set operationType(String t); external factory UserCredentialJsImpl( - {UserJsImpl user, AuthCredential credential}); + {UserJsImpl user, AuthCredential credential, String operationType}); } diff --git a/lib/src/interop/firebase_interop.dart b/lib/src/interop/firebase_interop.dart index 2f3866ef..6883889e 100644 --- a/lib/src/interop/firebase_interop.dart +++ b/lib/src/interop/firebase_interop.dart @@ -35,10 +35,18 @@ abstract class UserJsImpl extends UserInfoJsImpl { external PromiseJsImpl delete(); external PromiseJsImpl getToken([bool opt_forceRefresh]); external PromiseJsImpl link(AuthCredential credential); + external PromiseJsImpl linkWithCredential( + AuthCredential credential); external PromiseJsImpl linkWithPopup( AuthProviderJsImpl provider); external PromiseJsImpl linkWithRedirect(AuthProviderJsImpl provider); external PromiseJsImpl reauthenticate(AuthCredential credential); + external PromiseJsImpl reauthenticateWithCredential( + AuthCredential credential); + external PromiseJsImpl reauthenticateWithPopup( + AuthProviderJsImpl provider); + external PromiseJsImpl reauthenticateWithRedirect( + AuthProviderJsImpl provider); external PromiseJsImpl reload(); external PromiseJsImpl sendEmailVerification(); external PromiseJsImpl unlink(String providerId); diff --git a/pubspec.yaml b/pubspec.yaml index 610e479e..d1ba117d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: firebase description: Dart libraries for Firebase -version: 3.0.2 +version: 3.1.0 authors: - Jana Moudra - Kevin Moore diff --git a/test/app_test.dart b/test/app_test.dart index 08242c51..d75e7988 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -49,6 +49,10 @@ void main() { test("Get storage", () { expect(app.storage(), isNotNull); }); + + test("Get storage with a bucket", () { + expect(app.storage("gs://$storageBucket"), isNotNull); + }); }); test("Can be created with name", () { diff --git a/test/app_test.html b/test/app_test.html index a89d8835..2ac36acc 100644 --- a/test/app_test.html +++ b/test/app_test.html @@ -4,7 +4,7 @@ App Test - + diff --git a/test/auth_test.dart b/test/auth_test.dart index 117b005a..c57016fd 100644 --- a/test/auth_test.dart +++ b/test/auth_test.dart @@ -37,7 +37,7 @@ void main() { }); test('credential', () { var cred = EmailAuthProvider.credential('un', 'pw'); - expect(cred.provider, equals(EmailAuthProvider.PROVIDER_ID)); + expect(cred.providerId, equals(EmailAuthProvider.PROVIDER_ID)); }); }); @@ -51,7 +51,7 @@ void main() { }); test('credential', () { var cred = FacebookAuthProvider.credential('token'); - expect(cred.provider, equals(FacebookAuthProvider.PROVIDER_ID)); + expect(cred.providerId, equals(FacebookAuthProvider.PROVIDER_ID)); }); test('scope', () { var provider = new FacebookAuthProvider(); @@ -76,7 +76,7 @@ void main() { }); test('credential', () { var cred = GithubAuthProvider.credential('token'); - expect(cred.provider, equals(GithubAuthProvider.PROVIDER_ID)); + expect(cred.providerId, equals(GithubAuthProvider.PROVIDER_ID)); }); test('scope', () { var provider = new GithubAuthProvider(); @@ -101,7 +101,7 @@ void main() { }); test('credential', () { var cred = GoogleAuthProvider.credential('idToken', 'accessToken'); - expect(cred.provider, equals(GoogleAuthProvider.PROVIDER_ID)); + expect(cred.providerId, equals(GoogleAuthProvider.PROVIDER_ID)); }); test('scope', () { var provider = new GoogleAuthProvider(); @@ -127,7 +127,7 @@ void main() { }); test('credential', () { var cred = TwitterAuthProvider.credential('token', 'secret'); - expect(cred.provider, equals(TwitterAuthProvider.PROVIDER_ID)); + expect(cred.providerId, equals(TwitterAuthProvider.PROVIDER_ID)); }); test('custom parameters', () { var provider = new TwitterAuthProvider(); @@ -210,6 +210,48 @@ void main() { rethrow; } }); + + test('link anonymous user with credential', () async { + try { + user = await authValue.signInAnonymously(); + expect(user.isAnonymous, isTrue); + + var credential = + EmailAuthProvider.credential("some_user@example.com", "janicka"); + user = await user.linkWithCredential(credential); + expect(user.isAnonymous, isFalse); + expect(user.email, "some_user@example.com"); + } on FirebaseError catch (e) { + printException(e); + rethrow; + } + }); + + test('reauthenticate with credential', () async { + try { + user = await authValue.createUserWithEmailAndPassword( + "some_user@example.com", "janicka"); + + var credential = + EmailAuthProvider.credential("some_user@example.com", "janicka"); + await user.reauthenticateWithCredential(credential); + + expect(authValue.currentUser, isNotNull); + expect(authValue.currentUser.email, "some_user@example.com"); + } on FirebaseError catch (e) { + printException(e); + rethrow; + } + }); + + test('reauthenticate with bad credential fails', () async { + user = await authValue.createUserWithEmailAndPassword( + "some_user@example.com", "janicka"); + var credential = + EmailAuthProvider.credential("some_user@example.com", "something"); + + expect(user.reauthenticateWithCredential(credential), throws); + }); }); group('registered user', () { diff --git a/test/auth_test.html b/test/auth_test.html index fec7e98e..92649758 100644 --- a/test/auth_test.html +++ b/test/auth_test.html @@ -4,7 +4,7 @@ Authentication Test - + diff --git a/test/database_test.html b/test/database_test.html index d3b50acf..1a820656 100644 --- a/test/database_test.html +++ b/test/database_test.html @@ -4,7 +4,7 @@ Database Test - + diff --git a/test/storage_test.html b/test/storage_test.html index 54215f4e..ac29647c 100644 --- a/test/storage_test.html +++ b/test/storage_test.html @@ -4,7 +4,7 @@ Storage Test - +