Access scope data after Firebase authentication

2019-05-10 14:08发布

问题:

I authorized the calendar api in my google sign in auth, using the following code (Angularfire2):

let auth = new firebase.auth.GoogleAuthProvider();
    auth.addScope('https://www.googleapis.com/auth/calendar');
    this.afAuth.auth
      .signInWithPopup(auth).then((data) => {
        console.log(data); // nothing about calendar here
      });

Is there any way to access authorized scopes using FirebaseAuth?

For example, access the calendar data after the user signs and authorizes the calendar auth.

回答1:

If you check out the reference docs, you'll see that there are examples for each provider, which demonstrate how to obtain the third-party OAuth token:

// Using a redirect.
firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you a Google Access Token.
    var token = result.credential.accessToken;
  }
  var user = result.user;
});

Once you have the third-party token, you can use that directly against their APIs.