0

I am trying to do authentication to firebase server to get the details I used this when I was using angular 1.6

var fbRef = new Firebase(decodedUtSession.fburl);
fbRef.authWithCustomToken(decodedUtSession.fbtkn, function(error, authData) {
$rootScope.fbRef = fbRef;
if(error){
    console.log("Firebase Login Failed!", error);
  }
});

But Now I am upgrading my app to angular 6 with @angular/fire for firebase I tried the below code for custom auth but I am always getting invalidAuthTokeb though token is valid and working fine with the angular 1.6 app.

import { AngularFireAuth } from '@angular/fire/auth';
import { FirebaseAuth } from '@angular/fire';

constructor(private afAuth: AngularFireAuth) { }

 this.afAuth.auth.signInWithCustomToken(devToken).then((data) => {
     console.log(data);
 });

Can anyone please help me how to do authentication in a proper way TIA.

Rohit Kotak
  • 173
  • 1
  • 17
  • Are you sure you are passing the token correctly? can you please show the error as well? – Javier Aviles Oct 11 '18 at 13:45
  • @JavierAviles i am getting this error and yes auth token is correct one POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=xxxx 400 zone.js:192 Uncaught L {code: "auth/invalid-custom-token", message: "AUDIENCE_MISMATCH"} code: "auth/invalid-custom-token" message: "AUDIENCE_MISMATCH" __proto__: Error – Rohit Kotak Oct 11 '18 at 16:18
  • Can you go to https://jwt.io and decode your custom token? let's see whats inside... also make sure your front client has the same project_id as the backend project – Javier Aviles Oct 12 '18 at 08:39
  • @JavierAviles I am generating token in backend and then via api call i am getting that token and after passing token to signInWithCustomToken() I am getting that error. is there any other way to do custom auth in firebase with angular 6. – Rohit Kotak Oct 17 '18 at 07:37
  • If you want to do custom token auth, seems like the way to go – Javier Aviles Oct 18 '18 at 13:30

1 Answers1

0

Angular 2+ uses Firebase SDK3.0, so backend should also be upgraded to have authentication.

Rohit Kotak
  • 173
  • 1
  • 17