Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 94ca5bc

Browse files
author
Jacob Wenger
authored
Updated $signInWithPopup(), $signInWithRedirect(), and $signInWithCredential() docs (#896)
* Updated $signInWithPopup() and $signInWithRedirect() docs * Responded to Kato's feedback on auth ref docs updates
1 parent f2e8333 commit 94ca5bc

File tree

1 file changed

+91
-28
lines changed

1 file changed

+91
-28
lines changed

docs/reference.md

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,14 @@ for more details about email / password authentication.
686686

687687
### $signInWithPopup(provider)
688688

689-
Authenticates the client using a popup-based OAuth flow. This function takes two
690-
arguments: the unique string identifying the OAuth provider to authenticate with (e.g. `"google"`).
689+
Authenticates the client using a popup-based OAuth flow. This function takes a single argument: a
690+
a string or provider object representing the OAuth provider to authenticate with. It returns a
691+
promise which is resolved or rejected when the authentication attempt is completed. If successful,
692+
the promise will be fulfilled with an object containing authentication data about the signed-in
693+
user. If unsuccessful, the promise will be rejected with an `Error` object.
691694

692-
Optionally, you can pass a provider object (like `new firebase.auth.GoogleAuthProvider()`, etc)
693-
which can be configured with additional options.
695+
Valid values for the string version of the argument are `"facebook"`, `"github"`, `"google"`, and
696+
`"twitter"`:
694697

695698
```js
696699
$scope.authObj.$signInWithPopup("google").then(function(result) {
@@ -700,45 +703,100 @@ $scope.authObj.$signInWithPopup("google").then(function(result) {
700703
});
701704
```
702705

703-
This method returns a promise which is resolved or rejected when the authentication attempt is
704-
completed. If successful, the promise will be fulfilled with an object containing authentication
705-
data about the signed-in user. If unsuccessful, the promise will be rejected with an `Error` object.
706+
Alternatively, you can request certain scopes or custom parameters from the OAuth provider by
707+
passing a provider object (such as `new firebase.auth.GoogleAuthProvider()`) configured with
708+
additional options:
706709

707-
Firebase currently supports Facebook, GitHub, Google, and Twitter authentication. Refer to
708-
[authentication documentation](https://firebase.google.com/docs/auth/)
709-
for information about configuring each provider.
710+
```js
711+
var provider = new firebase.auth.GoogleAuthProvider();
712+
provider.addScope("https://www.googleapis.com/auth/plus.login");
713+
provider.setCustomParameters({
714+
login_hint: "[email protected]"
715+
});
716+
717+
$scope.authObj.$signInWithPopup(provider).then(function(result) {
718+
console.log("Signed in as:", result.user.uid);
719+
}).catch(function(error) {
720+
console.error("Authentication failed:", error);
721+
});
722+
```
723+
724+
Firebase currently supports [Facebook](https://firebase.google.com/docs/auth/web/facebook-login),
725+
[GitHub](https://firebase.google.com/docs/auth/web/github-auth),
726+
[Google](https://firebase.google.com/docs/auth/web/google-signin),
727+
and [Twitter](https://firebase.google.com/docs/auth/web/twitter-login) authentication. Refer to the
728+
linked documentation in the previous sentence for information about configuring each provider.
710729

711730
### $signInWithRedirect(provider[, options])
712731

713-
Authenticates the client using a redirect-based OAuth flow. This function takes two
714-
arguments: the unique string identifying the OAuth provider to authenticate with (e.g. `"google"`).
732+
Authenticates the client using a redirect-based OAuth flow. This function takes a single argument: a
733+
string or provider object representing the OAuth provider to authenticate with. It returns a
734+
rejected promise with an `Error` object if the authentication attempt fails. Upon successful
735+
authentication, the browser will be redirected as part of the OAuth authentication flow. As such,
736+
the returned promise will never be fulfilled. Instead, you should use the `$onAuthStateChanged()`
737+
method to detect when the authentication has been successfully completed.
715738

716-
Optionally, you can pass a provider object (like `new firebase.auth().GoogleProvider()`, etc)
717-
which can be configured with additional options.
739+
Valid values for the string version of the argument are `"facebook"`, `"github"`, `"google"`, and
740+
`"twitter"`:
718741

719742
```js
720743
$scope.authObj.$signInWithRedirect("google").then(function() {
721744
// Never called because of page redirect
745+
// Instead, use $onAuthStateChanged() to detect successful authentication
722746
}).catch(function(error) {
723747
console.error("Authentication failed:", error);
724748
});
725749
```
726750

727-
This method returns a rejected promise with an `Error` object if the authentication attempt fails.
728-
Upon successful authentication, the browser will be redirected as part of the OAuth authentication
729-
flow. As such, the returned promise will never be fulfilled. Instead, you should use the `$onAuthStateChanged()`
730-
method to detect when the authentication has been successfully completed.
751+
Alternatively, you can request certain scopes or custom parameters from the OAuth provider by
752+
passing a provider object (such as `new firebase.auth.GoogleAuthProvider()`) configured with
753+
additional options:
754+
755+
```js
756+
var provider = new firebase.auth.GoogleAuthProvider();
757+
provider.addScope("https://www.googleapis.com/auth/plus.login");
758+
provider.setCustomParameters({
759+
login_hint: "[email protected]"
760+
});
731761

732-
Firebase currently supports Facebook, GitHub, Google, and Twitter authentication. Refer to
733-
[authentication documentation](https://firebase.google.com/docs/auth/)
734-
for information about configuring each provider.
762+
$scope.authObj.$signInWithRedirect(provider).then(function(result) {
763+
// Never called because of page redirect
764+
// Instead, use $onAuthStateChanged() to detect successful authentication
765+
}).catch(function(error) {
766+
console.error("Authentication failed:", error);
767+
});
768+
```
769+
770+
Firebase currently supports [Facebook](https://firebase.google.com/docs/auth/web/facebook-login),
771+
[GitHub](https://firebase.google.com/docs/auth/web/github-auth),
772+
[Google](https://firebase.google.com/docs/auth/web/google-signin),
773+
and [Twitter](https://firebase.google.com/docs/auth/web/twitter-login) authentication. Refer to the
774+
linked documentation in the previous sentence for information about configuring each provider.
735775

736776
### $signInWithCredential(credential)
737777

738-
Authenticates the client using a credential (potentially created from OAuth Tokens). This function takes one
739-
arguments: the credential object. This may be obtained from individual auth providers under `firebase.auth()`;
778+
Authenticates the client using a credential. This function takes a single argument: the credential
779+
object. Credential objects are created from a provider-specific set of user data, such as their
780+
email / password combination or an OAuth access token.
740781

741782
```js
783+
// Email / password authentication with credential
784+
var credential = firebase.auth.EmailAuthProvider.credential(email, password);
785+
786+
$scope.authObj.$signInWithCredential(credential).then(function(firebaseUser) {
787+
console.log("Signed in as:", firebaseUser.uid);
788+
}).catch(function(error) {
789+
console.error("Authentication failed:", error);
790+
});
791+
```
792+
793+
```js
794+
// Facebook authentication with credential
795+
var credential = firebase.auth.FacebookAuthProvider.credential(
796+
// `event` come from the Facebook SDK's auth.authResponseChange() callback
797+
event.authResponse.accessToken
798+
);
799+
742800
$scope.authObj.$signInWithCredential(credential).then(function(firebaseUser) {
743801
console.log("Signed in as:", firebaseUser.uid);
744802
}).catch(function(error) {
@@ -750,9 +808,14 @@ This method returns a promise which is resolved or rejected when the authenticat
750808
completed. If successful, the promise will be fulfilled with an object containing authentication
751809
data about the signed-in user. If unsuccessful, the promise will be rejected with an `Error` object.
752810

753-
Firebase currently supports Facebook, GitHub, Google, and Twitter authentication. Refer to
754-
[authentication documentation](https://firebase.google.com/docs/auth/)
755-
for information about configuring each provider.
811+
Firebase currently supports `$signInWithCredential()` for the
812+
[email / password](https://firebase.google.com/docs/reference/node/firebase.auth.EmailAuthProvider#.credential),
813+
[Facebook](https://firebase.google.com/docs/reference/node/firebase.auth.FacebookAuthProvider#.credential),
814+
[GitHub](https://firebase.google.com/docs/reference/node/firebase.auth.GithubAuthProvider#.credential),
815+
[Google](https://firebase.google.com/docs/reference/node/firebase.auth.GoogleAuthProvider#.credential),
816+
and [Twitter](https://firebase.google.com/docs/reference/node/firebase.auth.TwitterAuthProvider#.credential)
817+
authentication providers. Refer to the linked documentation in the previous sentence for information
818+
about creating a credential for each provider.
756819

757820
### $getAuth()
758821

@@ -897,8 +960,8 @@ section of our AngularFire guide for more information and a full example.
897960
### $requireSignIn(requireEmailVerification)
898961

899962
Helper method which returns a promise fulfilled with the current authentication state if the user
900-
is authenticated and, if specified, has a verified email address, but otherwise rejects the promise.
901-
This is intended to be used in the `resolve()` method of Angular routers to prevented unauthenticated
963+
is authenticated and, if specified, has a verified email address, but otherwise rejects the promise.
964+
This is intended to be used in the `resolve()` method of Angular routers to prevent unauthenticated
902965
users from seeing authenticated pages momentarily during page load. See the
903966
["Using Authentication with Routers"](/docs/guide/user-auth.md#authenticating-with-routers)
904967
section of our AngularFire guide for more information and a full example.

0 commit comments

Comments
 (0)