如何使用Firebase实施Steam Auth?

时间:2017-06-26 11:03:37

标签: javascript node.js firebase firebase-authentication steam

我发现的只有这个旧答案:

https://groups.google.com/forum/#!topic/firebase-talk/rApG8QQd6t4

SOer的同事是否知道任何信息,或者Firebase工程师能否提供更详细的答案?

我目前正在尝试使用此库对Steam用户进行身份验证:

https://github.com/liamcurry/passport-steam

然后使用Firebase自定义令牌获取Firebase身份验证系统中的用户。

我不知道这是否是正确的方法。无论如何,我被困住了。

修改

这是我目前的代码:

app.js

var passport = require('passport');
var SteamStrategy = require('passport-steam').Strategy;

app.use(passport.initialize());

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  done(null, obj);
});

passport.use(new SteamStrategy({
    returnURL: 'http://localhost:8080/users/steam/return',
    realm: 'http://localhost:8080/',
    apiKey: steamKey.steam,
    stateless:true
  },
  function(identifier, profile, done) {

    profile.identifier = identifier;
    return done(null, profile);
  }
));

users.js

    router.get('/steam', passport.authenticate('steam', { failureRedirect: 'login' }), function(req, res, next) {

});

router.get('/steam/return', 
  function(req, res, next) {
      req.url = req.originalUrl;
      next();
  }, 
  passport.authenticate('steam', { failureRedirect: 'users/login' }),
  function(req, res) {
    console.log(JSON.stringify(req.query));
    var oid = req.query["openid.claimed_id"];
    var array = oid.split("/id/");
    console.log("Array: "+array);
    var result = array[1];
    console.log(result);
    admin.auth().createCustomToken(result)
      .then(function(customToken) {
         res.render("users/login",{token: customToken, passed: true});
      })
      .catch(function(error) {
        console.log("Error creating custom token:", error);
      });
});

用户/ login.ejs:

<a href="steam"><img id="steamLogin" src="../../public/assets/steamLogin.png"/></a>
    <script>

        if ("<%=passed%>" == "true") {
            firebase.auth().signInWithCustomToken("<%=token%>").catch(function(error) {
                if (error) {
                    alert(error);
                }
                else {
                    res.redirect("screenshots/index");
                }

            });   
        }  

    </script>

我目前的问题如下:

1)这有效但将Steam声明的ID公开为用户的公共UID。公开用户声明的ID是否安全?这是否意味着任何人都不能通过使用他声称的身份证明我的用户?

2)&#34;标识符&#34;在我的Firebase Auth仪表板中。在登录用户时如何指定标识符?

3)事实上,在创建自定义令牌时我应该将uid用作什么?

1 个答案:

答案 0 :(得分:1)

您这样做的方式是正确的,正如 another question 中所述,“Firebase 支持使用任何提供商登录,只要您愿意为其编写代码。” .对于有兴趣实施 Steam 身份验证的任何人,该问题还为文档提供了 link 来执行此操作。解释一下,firebase 支持开箱即用的某些身份验证提供程序,当它不支持身份验证提供程序时,您需要编写自己的身份验证代码,这是一个生成身份验证令牌的过程。链接的文章解释了您应该如何生成令牌。