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 provider
123.apps.googleusercontent.com Web Client ID authDomain www.googleapis.com, idTokenidToken , ..- , + , ,
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...