1

我正在尝试为我的门户编写一个 FirefoxOS 应用程序,该应用程序使用 Mozilla Persona 进行身份验证。如果我想实现,我应该如何进行:

  • 允许我的应用用户使用 Persona 注册我的门户
  • 允许我的应用程序的用户在 FirefoxOS 应用程序中登录我的门户并使用 API 执行一些操作
  • 取决于用户是否登录 - 授予对不同操作的访问权限。

我发现这篇文章的信息已经集成:http: //identity.mozilla.com/post/47114516102/persona-on-firefox-os-phones但我找不到任何真实的例子。

我需要创建什么类型的应用程序?webapp 还是特权?

我正在尝试使用常规教程来实现它:https ://developer.mozilla.org/en/Persona/Quick_Setup

但是有了这段代码:

  signinLink.onclick = function() { navigator.id.request(); };

我只收到以下错误:

[17:25:18.089] Error: Permission denied to access object
4

1 回答 1

2

一件事是确保在调用watch()之前调用设置回调request()

例如,在您的页面中是这样的:

<script src="https://login.persona.org/include.js"></script>
<script>
  window.addEventListener("DOMContentLoaded", function() {
    navigator.id.watch({
      // Provide a hint to Persona: who do you think is logged in?
      loggedInUser: null,

      // Called when persona provides you an identity assertion
      // after a successful request().  You *must* post the assertion
      // to your server for verification.  Never verify assertions
      // in client code.  See Step 3 in this document:
      // https://developer.mozilla.org/en/Persona/Quick_Setup
      onlogin: function(assertion) {
        // do something with assertion ...
        // Note that Persona will also call this function automatically
        // if a previously-signed-in user visits your page again.
      },

      onlogout: function() {
        // handle logout ...
      },

      onready: function() {
        // Your signal that Persona's state- and callback-management
        // business is complete.  Enable signin buttons etc.
      }
    });

    // Set up click handlers for your buttons
    document.getElementById("signin").addEventListener(
      'click', function() {
        navigator.id.request({
          // optional callback to request so you can respond to
          // a user canceling the sign-in flow
          oncancel: function() {  /* do something */ }
        });
      }
    });
  });
</script>

下面是一个例子,展示了这一点:

https://people.mozilla.org/~jparsons/persona_example.html

但是,在 FirefoxOS 上,您应该知道已安装的应用程序(未打包或认证,而是通用安装的应用程序)具有唯一的表单来源,app://{uuid}每个设备具有不同的 uuid。不幸的是,这对于登录目的毫无用处,因为您的服务器无法知道请求登录的应用程序是朋友还是敌人。解决此问题的方法是在服务器上托管的不可见 iframe 中运行您的角色代码。因此 iframe 将具有正确的来源,并且您的服务器将知道它是您的应用程序。iframe 和应用程序可以通过 postMessage 进行通信。

对于打包的应用程序(有时称为特权应用程序),您的来源将是您的 webapp 清单中声明的​​来源。例如,app://yourapp.yoursite.org。这可以让您更好地确保应用程序确实是您的,但真正偏执的人可能仍希望部署 iframe 技巧。

希望这可以帮助!j

于 2014-03-03T18:26:07.303 回答