Clone wiki

mod_openid / Notify

mod_openid notifications

Zotonic notification mechanism is a z_notifier server and it's API for sending async.broadcast/sync.unicast messages to other subscribed modules. mod_openid implements several notifications. Most of them are "questions", that need answers.

Following Table describes all messages. It has 6 columns:

  • N - this table row number.
  • message - z_notifier message body.
  • ? - is call synchronous? True means, than mod_openid wants to see the answer from first message observer. The answer format is decribed in result format column.
  • description.
  • result format - if call synchronous, proper data in <result format> must be received. If call is asynchronous, then all observers of message will be notified and all results are ignored.
  • example result - example of proper result for synchronous call, returned by first observer; erlang term.
Nmessage?descriptionresult format
example result
1{signup_url, RscProps, SignupProps}+Standard mod_signup's XS-interface call. When XS-signup method is enabled, this message will be fired by mod_openid to find any signup URL.
- RscProps -- proplists; contains some personal information about user (name_first, phone, etc).
- SignupProps -- list of 2-element tuples; every tuple contains complete user identification info in mod_signup's identity format: {ident, Data}, data is {Type, Id, IsVerified, IsUniq}. So, example mod_openid's SignupProps = [{identity, {openid,"",true,true}}].
{ok, SignupUrl::string()}

{ok, "/signup?xs=123ABCDEF"}
2{logon_ready_page, []}+Already registered user is returned from Provider and automatically logged on by mod_openid. At the moment, user's browser stays on /logon/openid/return?openid.signature=...&... and waiting for any http-responce. User MUST be redirected somewhere, because mod_openid does not providing any content.
mod_openid fires this messsage to observe the URL for temporarily redirect (HTTP 307). If no result, mod_openid will redirect user to /.
This call is also fired by mod_authentification if some user logged on via username/password.

3{signup_confirm_redirect, UserId::int()}+Every user has it's first logon. This call requests the redirect URL for new user. mod_openid fires signup_confirm_redirect only if fast signup enabled; else this call will be fired by mod_signup later.
See also row #2 of this table.

4{prepare_signup_rsc_props, {mod_openid, RscProps}}+Current limitation of erl_openid is absence of sreg/AX. When user is returned from Provider first time, the provider's responce is decoded by mod_openid. The rsc title and other data is extracted from provider's responce. By now, title is set to OpenID identity string.
This call may overwrite the RscProps. After this call, RscProps is passed to mod_signup (see row #1) or used to directly create new rsc.

[{title, "Mr.Putin"},...]
5{render_logon_error, {mod_openid, Error}}
Error is a 'timeout' atom or other error
+Sometimes mod_openid unable to connect to user's Provider. This is a early logon error. This error may occur only between events <user submitted claimed openid identity> and <mod_openid received redirect tokens>. Event observer (your site) MAY handle this event and render something (or suppress any rendering).
If no result, then z_render:growl_error/2 will be called by mod_openid and with console output, so user and site administator will be notified by error

Make own notifications observer

For example, you want to redirect all logged users to page "/welcome". To do it, you need to implement message handing for logon_ready_page (row #2 of notifications table).

Your site project is named mysite, so project folder is priv/sites/mysite and site module is mysite.erl in project folder. Merge following code to your mysite.erl:


observe_logon_ready_page({logon_ready_page, _}, _Context) -> "/welcome".

That is all. Too easy, huh?

After z:m() and z:restart() mod_openid will redirect logged-on users to "/welcome" page. Of couse, you should NOT use string constants is source code, you will use z_dispatcher:url_for() to generate any URL.

Same approach may be used for other messages from table.