Hey Mounir! Thank you for the careful feedback!
On Apr 16, 2012, at 8:56 AM, Mounir Lamouri wrote:
> On 04/09/2012 07:18 PM, Lloyd Hilaiel wrote:
> Hi,
>
> I think we could make use of the DOMRequest object here. For
> information, most of the new APIs made from the WebAPI effort are using
> a pattern like this for async calls:
> DOMRequest method(argument);
>
> You can find the DOMRequest interface here:
>
https://mxr.mozilla.org/mozilla-central/source/dom/base/nsIDOMDOMRequest.idl
>
> For example, the request() method (that I would name login()) could
> return a DOMRequest object and a 'success' event would fire if the login
> succeeded or an 'error' event otherwise like:
>
> var request = navigator.id.login(null, null, null);
> request.onsuccess = function() { alert("successfully logged in!"); };
> request.onerror = function() { alert("failed to login..."); };
I read several of the proposed APIs built on top of DOMRequest, and really appreciate
the attempt to apply a concrete pattern to asynchronous requests in these emerging APIs
(oh yeah, and can't *wait* till we can play with this stuff in apps).
That said, I'm having trouble seeing that this is the most intuitive interface for persona.
One key reason I don't feel that it fits here is that "login" can happen multiple times
while the page is loaded - and it can happen as a result of the page requesting it
(page can request an id from the user), or can occur out of band (user signs up for persona and
simultaneously logs into the site, but not while the site is loaded).
This pattern seems to apply best to a asynchronous request. (like navigator.contacts.save(),
or WiFiManager.getNetworks() for instance).
> The same idea could be used for navigator.id.logout().
>
> In addition, IMO, navigator.id.watch() isn't very webby. We could
> probably use the good old event listeners here instead.
> That would create 3 events named 'login', 'logout' and 'ready' and three
> event handlers name id.onlogin, id.onlogout and id.onready.
Yeah! We actually started with an "eventy" API, however several things don't
really fit:
* there isn't really a 1-1 correspondence between an event occurring, and the client
getting notified. if we used events, the raised events wouldn't temporally correspond to the
event occurring - which is weird and I can't find any precedent for this.
* assertion generation (for the login event) can have a significant cost (computation and
network requests), and is only necessary *sometimes*, not at every page load. Every attempt
to plug this hole led to a clumsy API that was harder to explain. (we would probably end up
forcing pages to do something unnatural to tell us who the currently logged in user is -
requiring they do server side substitution and serve non-cachable resources).
Here's the (presently aborted) attempt at a more event based api:
http://lloyd.io/a-new-api-for-browserid
> It's not clear to me what the |email| parameter is for in |watch|. If
> the only idea is to filter events, we could allow web developers to do
> that by themselves.
I will try to make this much clearer in the next pass of API docs (to be completed today),
and we've already decided to rename this parameter. Maybe you're a perfect guinea pig, if
the parameter was named 'loggedInUser' and you knew the site provided it, would the intent
be clearer?
The idea is because there's a non-trivial cost to generating a "login" event every time,
it's worth surfacing the "filtering" parameter in the API. Further, because even though
webdevs could filter at a later point, this would not allow them to avoid the cost at
page load time.
Generally, however, I strongly prefer leaving filtering up to the site, and for certain features
(like websites that require an email address from a certain domain to log in), I think this
is the right approach.
> Which actually leads to another question: how an API consumer knows the
> currently logged in user with that API? Is that hidden on purpose?
> Otherwise, should we expose this in navigator.id.something or add an
> attribute to the event object sent with login/logout events?
Historically we've hidden it because we have been scared that websites would just
*trust* an email address handed back by browserid. Previous discussions have focused
more on the fact that our callbacks never return bare emails and instead return
assertions that the client must verify on their server. Here's a long thread on the
topic:
https://groups.google.com/group/mozilla.dev.identity/browse_thread/thread/bc2e047281ccc80b/de3c6d729791fcc7?lnk=gst&q=email+from+assertion#de3c6d729791fcc7
In this case though, I'm most concerned that the api itself makes the following clear:
1. you must handle out of band login/logout events (which occur when your page is not loaded)
2. you should tell the api what email you think is logged in so you're not generating assertions
every page load.
Do these motivations make sense to you?
lloyd
> Cheers,
> --
> Mounir