How to get accessToken for firebase 3 using javascript
11,067
Solution 1
firebase.auth().signInWithEmailAndPassword(u, p).then(function(result){
result.getToken().then(function(token){
$rootScope.userLoginToken = token;
});
});
Solution 2
The access token is no longer available in the authData when you're using version 3.x of the SDK. But you can get is when the user gets authenticated with.
var auth = firebase.auth();
var provider = new firebase.auth.GoogleAuthProvider();
auth.signInWithPopup(provider).then(function(result) {
var accessToken = result.credential.accessToken;
});
For this and a lot more information that is relevant when migrating your web app, see the upgrade guide for web apps (where I copied the code from).
Related videos on Youtube
Author by
Stradosphere
Full stack developer versed in a broad spectrum of technologies
Updated on September 14, 2022Comments
-
Stradosphere almost 2 years
I need to make a shallow rest call using javascript with firebases REST Api, in the past version I needed to pass the access token like this:
var authKey = ref.getAuth().token; var s = firebaseUrl + '/.json?shallow=true&auth=' + authKey; $http.get(s)
How do I do this now with firebase 3?
-
Stradosphere about 8 yearsFrank I can't seem to get result.credential using firebase.auth().signInWithEmailAndPassword(), do I need to use another method? I'm justing using email/password auth method
-
Frank van Puffelen about 8 yearsThere is no access token when you're using email and password. It sounds like you might be looking for @stradosphere's answer.
-
Vitali Kniazeu about 7 yearsIsn't there a limitation now with
credential.accessToken
being exposed only during the login flow? If the user is already authenticated, the login routine never runs while the app uses saved auth data.