最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get accessToken for firebase 3 using javascript - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Jun 24, 2016 at 1:35 Frank van Puffelen 599k85 gold badges888 silver badges858 bronze badges asked Jun 24, 2016 at 1:11 StradosphereStradosphere 1,2853 gold badges14 silver badges40 bronze badges 1
  • just to clarify, this is asking about the firebase jwt token and not the auth provider's access token. The firebase jwt token is used for firebase authentications and the auth provider's access token is used for provider authentication and accessing the provider's apis (e.g. drive API for google) – Jason Commented Dec 7, 2021 at 23:10
Add a comment  | 

2 Answers 2

Reset to default 13
firebase.auth().signInWithEmailAndPassword(u, p).then(function(result){

    result.getToken().then(function(token){
        $rootScope.userLoginToken = token;
    });

});

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).

发布评论

评论列表(0)

  1. 暂无评论