My last week has been quite busy, but it all paid off in the end as I’ve managed to overcome the issue that I had with the login phase. Thankfully, I was able to take a look at how the postMessage() API is used to do the login in Firefox iOS and implement it myself in Epiphany.
To summarize it, this is how it’s done:
- Load the FxA iframe with the service=sync parameter in a WebKitWebView.
- In the event listener use postMessage() to send to back to WebKit the data received from the server.
- In the C code, register a script message handler with a callback that gets called whenever something is sent through the postMessage() channel. This is done with webkit_user_content_manager_register_script_message_handler().
- In the callback you now hold the server’s response to your request. This includes all the tokens you need to retrieve the sync keys.
With this new sign in method, users can also benefit of the possibility to create new Firefox accounts. The iframe contains a “Create an account” link that shows a form by which the users will create a new account. The user will have to verify the account before he signs in.