Authentication with signInWithCredential ()

I am trying to connect to a second Firebase application and authenticate with signInWithCredential(), but I do not know how to get valid for the second application: idToken

  connect(accessToken: string, config: FirebaseAppConfig) {
    let one: firebase.app.App = this.angularFireTwo.database["fbApp"];
    one.auth().currentUser.getToken()
      .then(idToken => firebase.auth.GoogleAuthProvider.credential(idToken, accessToken))
      .then(credential => {
        let two = firebase.initializeApp(config, `[${config.apiKey}]`);
        return two.auth().signInWithCredential(credential);
      })
      .catch(console.warn)
      .then(console.info);
  }

I get and error from https://www.googleapis.com/identitytoolkit/v3/:

Invalid id_token in IdP response

If I use signInWithPopup(), I can do authentication and connection:

        two.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())

Does anyone know what should I do to get a valid idToken?


UPDATE:

I tried to figure out the authentication process and, as far as I understood, this is something like this:

  • from config: FirebaseAppConfigfirebase reads apiKeyandauthDomain
  • it contacts the servers and receives the web client ID for the included Google provider123.apps.googleusercontent.com
  • Web Client ID authDomain www.googleapis.com, idToken
  • idToken , ..
  • , + , , idToken - accessToken

, signInWithPopup(), 2-3-4 ( ). idToken 4, firebase.auth.GoogleAuthProvider.credential(idToken, accessToken) signInWithCredential().

, - ; apiKey, authDomain, - 456.apps.googleusercontent.com accessToken.

, . - authations, , idToken s, , t work...

+4
1

: firebase.auth.GoogleAuthProvider.credential(idToken, accessToken))

OAuth Google. Firebase Id, . , , signInWithCredential?

Google, OAuth Google, OAuth Google.

Firebase OAuth , signInWithPopup InWithCredential .

two.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider()) .then(function(result) { return one.auth().signInWithCredential(result.credential); });

+4

Source: https://habr.com/ru/post/1657880/


All Articles