I am trying to use signInWithCustomToken to Login
Bootstrap is setup like this:
firebaseAuthConfig({
provider: AuthProviders.Custom,
method: AuthMethods.CustomToken,
})
And my code is like this
this.af.auth.login({ token });
But I am getting this kind of error:
error TS2345: Argument of type '{ token }' is not assignable to parameter of type 'EmailPasswordCredentials | AuthCredential | string'.
Object literal may only specify known properties, and 'token' does not exist in type 'EmailPasswordCredentials | AuthCredential | string'.
@dmastag you should use this -
this.af.auth.login( token );
i.e. only pass the string and not the object. There is a change in the parameter type in Firebase 3
@ksachdeva I am getting the following Error when doing that
EXCEPTION: Error: Uncaught (in promise): You must include credentials to use this auth method.
Is there anything I am missing ?
For the record, I have no problem if using the same token directly, using:
firebase.auth().signInWithCustomToken(token)
Could it be that I've setup the wrong provider?
@dmastag
I have never used the customToken auth before but looking at the source code, it seems that the login method is waiting for another parameter.
Try passing an empty config as the second parameter like this:
this.af.auth.login(token, {})
@dmastag
Below is what is working for me (there are problems once the token is submitted to Firebase which I will describe in a separate issue but this will get you to submit the token)
this.fbAuth.login(authToken, {
provider: AuthProviders.Custom,
method: AuthMethods.CustomToken
});
I am getting this exception:
EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'providerId' of undefined
I've put this into my constructor:
constructor(af: AngularFire) {
af.auth.subscribe(auth => console.log(auth ));
af.auth.login(localStorage.getItem('fbToken'), {
provider: AuthProviders.Custom,
method: AuthMethods.CustomToken,
});
}
Are you on Beta.2 also ?
Correct. I am also getting this error. Please see this - https://github.com/angular/angularfire2/issues/292
AngularFire2 is expecting providerData and providerId but when we are doing custom token authentication Firebase is returning provderdata array with length 0. I am not sure whose bug it is - Firebase or AngularFire2 ? A temporary fix in AngularFire2 can be done to not rely on providerData when doing custom authentication but cleaner approach will be if Firebase returns the providerId as 'custom'
@ksachdeva @dmastag
This is an issue in the way Custom Login provider data has changed in Firebase 3.0. The current code base relies on that provider data existing when it can now be null. We'll work on getting this fix.
Hi David,
I have created a repository as an example to demonstrate the custom authentication. As you already know that there is a bug with the providerId. I thought it would be helpful to test the modification when you will fix the bug. There is a readme that describes all the necessary setup etc as well
https://github.com/ksachdeva/firebase-custom-auth-example
Regards & thanks
Kapil
Hi David,
Here is a pull request for this issue/bug :
https://github.com/angular/angularfire2/pull/301
that contains the fix for the issue. The CI is failing but I do not think it is because of my modifications; seems like a build issue.
I did run the tests locally and they all are passing.
Regards
Kapil
Is there any workaround for this for now? I am trying to integrate my app with auth0 custom tokens.
@npradeeptha you either try the pull request #301 or you use firebase without angularfire for the authentication
Thank you! I wasn’t aware I could you both firebase and angularfire2 in tandem.
From: Julian Alimin [mailto:[email protected]]
Sent: Tuesday, July 05, 2016 5:32 PM
To: angular/angularfire2
Cc: Perera, Nipuna; Mention
Subject: Re: [angular/angularfire2] How to get signInWithCustomToken working ? (#286)
@npradeepthahttps://github.com/npradeeptha you either try the pull request #301https://github.com/angular/angularfire2/pull/301 or you use firebase without angularfire for the authentication
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/angular/angularfire2/issues/286#issuecomment-230622016, or mute the threadhttps://github.com/notifications/unsubscribe/ALCfFqoGptktSV-IimVfsBz-RT2CEBbyks5qSttggaJpZM4I-aVR.
Any update here?
@hunterleaman Working on it for the next release.
Most helpful comment
@hunterleaman Working on it for the next release.