简体   繁体   English

如何使用javascript获取firebase 3的accessToken

[英]How to get accessToken for firebase 3 using javascript

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: 我需要使用带有firebase REST Api的javascript进行浅休息调用,在过去的版本中我需要传递访问令牌,如下所示:

    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? 我现在如何使用firebase 3执行此操作?

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. 当您使用SDK的3.x版时,authData中不再提供访问令牌。 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). 对于此以及迁移Web应用程序时相关的更多信息,请参阅Web应用程序的升级指南 (我从中复制代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM