有一件事是使確定您在致電request()
之前致電watch()
設置回撥。
例如,這樣的事情在你的頁面:
<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進行通信。
對於打包應用程序(有時稱爲特權應用程序),您的來源將是您的web應用程序清單中聲明的來源。例如,app://yourapp.yoursite.org
。這可以讓你更好地保證應用程序真的是你的,但真正的偏執狂可能仍然希望部署iframe技巧。
希望這會有所幫助! j
因此,如果我理解正確 - 我應該將身份驗證過程暴露給我的網頁,從而在我的網頁上運行這些JavaScript,而不是直接在設備上運行? – bluszcz
您將始終在設備上運行watch()和request()。在您沒有特權應用的情況下,我建議運行watch()和request()的代碼可以位於從您的網頁提供的iframe中。但第一步就是讓watch()和request()在你從FirefoxOS或任何其他瀏覽器訪問的網頁中正常工作。那是行得通嗎? –
登錄個人空間到我的網站它的工作原理。現在,我設法使其工作 - 從移動。現在我必須同步在門戶網站上與唱歌應用程序簽約移動 - 我可以通過Persona和我的應用程序登錄到我的網站。必須找出如何傳遞用戶登錄信息的最佳方式。謝謝! – bluszcz