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

Commit

Permalink
New release (#104)
Browse files Browse the repository at this point in the history
* Latest firebase update
* Updates in auth
* Support for storage buckets
* AuthCredential provider deprecated
* Deprecated message
  • Loading branch information
Janamou authored and kevmoo committed Apr 27, 2017
1 parent 685c6d8 commit f198ee4
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 25 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You must include the original Firebase JavaScript source into your `.html` file
to be able to use the library.

```html
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
```

### Use it
Expand Down
2 changes: 1 addition & 1 deletion example/auth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 id="auth_info" style="display: none">
</h2>
<a href="#" id="logout_btn" style="display: none">Log out</a>
</div>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="index.dart" type="application/dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion example/realtime_database/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>Messages demo</h1>
<input type="submit" value="Send" id="submit" disabled>
</form>
</div>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="index.dart" type="application/dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion example/storage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>Upload image demo</h1>
</form>
<p id="message"></p>
</div>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="index.dart" type="application/dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
Expand Down
8 changes: 6 additions & 2 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class App extends JsObjectWrapper<AppJsImpl> {
/// 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);
}
}
52 changes: 45 additions & 7 deletions lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ class User extends UserInfo<firebase_interop.UserJsImpl> {
Future<String> 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<User> 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<User> 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.
Expand All @@ -99,11 +105,29 @@ class User extends UserInfo<firebase_interop.UserJsImpl> {
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<UserCredential> 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());
Expand Down Expand Up @@ -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<UserCredentialJsImpl> {
User _user;

Expand Down Expand Up @@ -500,10 +526,22 @@ class UserCredential extends JsObjectWrapper<UserCredentialJsImpl> {
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/interop/app_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ abstract class AppJsImpl {
external AuthJsImpl auth();
external DatabaseJsImpl database();
external PromiseJsImpl delete();
external StorageJsImpl storage();
external StorageJsImpl storage([String url]);
}
9 changes: 8 additions & 1 deletion lib/src/interop/auth_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ abstract class AuthJsImpl {
/// See: <https://firebase.google.com/docs/reference/js/firebase.auth.AuthCredential>.
@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;
}
Expand Down Expand Up @@ -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});
}
8 changes: 8 additions & 0 deletions lib/src/interop/firebase_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ abstract class UserJsImpl extends UserInfoJsImpl {
external PromiseJsImpl delete();
external PromiseJsImpl<String> getToken([bool opt_forceRefresh]);
external PromiseJsImpl<UserJsImpl> link(AuthCredential credential);
external PromiseJsImpl<UserJsImpl> linkWithCredential(
AuthCredential credential);
external PromiseJsImpl<UserCredentialJsImpl> linkWithPopup(
AuthProviderJsImpl provider);
external PromiseJsImpl linkWithRedirect(AuthProviderJsImpl provider);
external PromiseJsImpl reauthenticate(AuthCredential credential);
external PromiseJsImpl reauthenticateWithCredential(
AuthCredential credential);
external PromiseJsImpl<UserCredentialJsImpl> reauthenticateWithPopup(
AuthProviderJsImpl provider);
external PromiseJsImpl reauthenticateWithRedirect(
AuthProviderJsImpl provider);
external PromiseJsImpl reload();
external PromiseJsImpl sendEmailVerification();
external PromiseJsImpl<UserJsImpl> unlink(String providerId);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firebase
description: Dart libraries for Firebase
version: 3.0.2
version: 3.1.0
authors:
- Jana Moudra <jana.moudra@gmail.com>
- Kevin Moore <kevmoo@google.com>
Expand Down
4 changes: 4 additions & 0 deletions test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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", () {
Expand Down
2 changes: 1 addition & 1 deletion test/app_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>App Test</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="packages/test/dart.js"></script>
<link rel="x-dart-test" href="app_test.dart">
</body>
Expand Down
52 changes: 47 additions & 5 deletions test/auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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', () {
Expand Down
2 changes: 1 addition & 1 deletion test/auth_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Authentication Test</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="packages/test/dart.js"></script>
<link rel="x-dart-test" href="auth_test.dart">
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/database_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Database Test</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="packages/test/dart.js"></script>
<link rel="x-dart-test" href="database_test.dart">
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/storage_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Storage Test</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/3.7.8/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script src="packages/test/dart.js"></script>
<link rel="x-dart-test" href="storage_test.dart">
</body>
Expand Down

0 comments on commit f198ee4

Please sign in to comment.