使用Firebase委派验证0

使用Firebase委派验证0,firebase,firebase-security,auth0,firebase-authentication,Firebase,Firebase Security,Auth0,Firebase Authentication,使用firebase委派进行Auth0登录 .controller('LoginCtrl', function($scope, auth, $state, store) { auth.signin({ authParams: { // This asks for the refresh token // So that the user never has to log in again scope: 'op

使用firebase委派进行Auth0登录

.controller('LoginCtrl', function($scope, auth, $state, store) {
      auth.signin({
        authParams: {
          // This asks for the refresh token
          // So that the user never has to log in again
          scope: 'openid offline_access',
          // This is the device name
          device: 'Mobile device'
        },
        // Make the widget non closeable
        standalone: true
      }, function(profile, token, accessToken, state, refreshToken) {
        // Login was successful
        // We need to save the information from the login
        store.set('profile', profile);
        store.set('token', token);
        store.set('refreshToken', refreshToken);
        auth.getToken({
          api: 'firebase'
        }).then(function(delegation) {
          store.set('firebaseToken', delegation.id_token);
          $state.go('app.categories');
        }, function(error) {
          console.log("There was an error getting the firebase token", error);
        })
      }, function(error) {
        console.log("There was an error logging in", error);
      });
    })
在Auth0处为令牌的委托部分分配适当uid的规则:

function (user, context, callback) {
  var isFirebase = context.request.body.api_type === "firebase";
  if (context.isDelegation && isFirebase) {
    console.log(user.user_id);
    var uid = user.user_id;
    var provider = uid.split("|")[0];
    var id = uid.substring(uid.indexOf("|") + 1);
    user.firebase_data = {
      uid: provider + ":" + id
    };
  }
  return callback(null, user, context);
}
令牌作为uid的证明(如解码令牌中firebase的预期)

正在尝试使用UID:e./users/facebook | 34234规则向Firebase中的/users/$users写入数据:

{
    "rules": {
      "users": {
        "$user_id": {
          // grants write access to the owner of this user account
          // whose uid must exactly match the key ($user_id)
          ".write": "$user_id === auth.uid"
        }
      },
      "salt" : {
       ".read" : true,
       ".write" : false
      },
      "categories" : {
       ".read" : true,
       ".write" : false
      },
        ".read": true,
        ".write": false
    }
}
不幸的是,我似乎无法调试firebase端发生的事情。据我所知,Firebase希望Firebase令牌的委托对象中包含uid,但在此提供的任何帮助都将不胜感激

当我用适当的用户信息交换auth.uid(在Firebase规则中)时,信息会被写入,因此我相信,如果我能在令牌内以某种方式将适当的uid传递给Firebase,这一切都会实现

是的,我打算在uid中使用:而不是|作为分隔符。这是基于Firebase的预期


对加藤问题的答复:


@Kato Auth0使用委托的概念来生成Firebase令牌。该令牌存储在客户端的浏览器上。解码时,令牌看起来像上面贴的块(证明令牌包含uid…)。firebase文档表明uid是
provider:id
,但是,您发送给我的最后一篇文章表明uid只是唯一生成的字符串

我想我不明白auth0的责任从哪里开始,firebase的责任从哪里结束?为什么我甚至需要从auth0委派令牌?我是否应该单独调用firebase来生成令牌?如何处理Auth0创建的firebase令牌

这对我来说真正有趣的是,Auth0和Firebase的人似乎都不理解我所问的问题,可能是因为我问的方式不对


基本上,我只想用Auth0对我的用户进行身份验证,然后让Firebase保护数据库中的端点。

我解决了这个问题,并将它写在这里:

当你提到这一点时:“当我用适当的用户信息交换auth.uid(在Firebase规则中)时”,你用哪个ID替换它?您是否正在硬编码“facebook:10153081497714658”?Auth0是否已经提供Firebase令牌作为选项?我很确定他们有一个Firebase集成。另外,尝试创建看起来像Firebase内部实现的UID。您从Firebase得到了什么错误?authWithOAuthToken()或authWithCustomToken()调用在哪里?Auth0是否也为您完成此部分?我认为不是。@katoauth0使用委托的概念来生成Firebase令牌。该令牌存储在客户端的浏览器上。当解码时,令牌看起来是这样的:{“iss”:“sub”:“facebook | 10153081497714658”,“aud”:“ZCCZRJ0GGURK67Eph2ughtSL9FKFPMLCS”,“exp”:143899556,“iat”:143895356,“v”:0,“d”:{“FBU id”:“facebook | 10153081497714658”,“uid”:“facebook:10153081497714658”},“AZCP”:“ZCCZCCZRJ0GGURK67Eph2FK9FKMLCS”}`以下是错误:FIREBASE警告:设置为/users/facebook:10153081497714658/0/-JwJPCfwkBc5Zw4zOBWY失败:权限被拒绝
{
    "rules": {
      "users": {
        "$user_id": {
          // grants write access to the owner of this user account
          // whose uid must exactly match the key ($user_id)
          ".write": "$user_id === auth.uid"
        }
      },
      "salt" : {
       ".read" : true,
       ".write" : false
      },
      "categories" : {
       ".read" : true,
       ".write" : false
      },
        ".read": true,
        ".write": false
    }
}