cURL Dual Login
By Henk Wevers (www.breincoach.com)
At this time the following plugins use the cURL mechanism for Dual Login;
- Magento
- Moodle
- Joomla_ext
- SMF
- DokuWiki
- osCommerse (2.x and 3.x)
- xtCommerce (3.x)
- Kayako
How dual login works
When a user logs in on the Joomla login screen, the user is first validated using the masters user data. If the user is a valid user, this user is logged in to Joomla and then to all other activated plugins using the smart cURL Jfusion library. Parameter settings for the plugin will control how the plugin uses this cURL library to log in to the integrations.
Appendix 1 lists all available cURL parameters with their defaults. There is room to fill in your specific parameters if your setup or templates differ from the default installation of the integration. Note that in the majority of the cases the default values will work.
Below I will point out how you can find out which parameters have to be adapted while describing the methods the smart cURL routines use to log in and out.
Step 1. Find a valid login form
Firstly the routines try to find a valid login form. The URL where the routines search is made from the “full URL to the integrated software” set by the wizard and the cURL parameterlogin_url. So if your integrated website has a base URL www.yourdomain.com/moodle and the login form is on www.yourdomain.com/moodle/login then the parameter login_urlshould be set to login. Mostly the loginform is on the front-page, in this case the parameter is left empty.
Secondly the routines try to find the login form by means of the name or ID of the form. If you have modified your login form and given it a different name and ID then you surely know the data to overwrite the default value of the parameter loginform_id.
Step 2. Find out how to post the login data
Once the login form is found, the routines try to find the names of the username and password fields. As most login forms use ‘name’ as part of the identification of the username field and ‘pass’ as the part of the password field the routines will find the needed data in 90% of all cases, so you can leave the parameters input_username_id and input_password_id empty as a start. If the routines cannot find valid IDs, you will get an error message stating the fields found in the login form so you can adapt above parameters.
Now the login form will search for essential data needed to login. These are hidden fields and button information.
Finally the form is searched for the URL to post the login data. This URL can be a full URL (http://.……) or an URL relative to the base URL. This can be specified with the relpath parameter.
As said, in most installations the default parameters will work, But if you have a heavily modified login form you probably need to adjust these parameters. An easy way to find out what you need to fill in is to point your browser to the login screen, display the page source and search for the login form using the string “<form”.
<form action="http://www.jfusion.org/index.php"method="post"name="login"> <input type="text"name="username"size="18"alt="Username"value=""/> <input type="password"name="passwd"size="10"alt="Password"value=""/> <input type="hidden"name="remember"value="yes"/> <button value="Login"name="Submit"type="submit"title="Log">Loginbutton> <input type="hidden"name="option"value="com_user"/> <input type="hidden"name="task"value="login"/> <input type="hidden"name="return"value="aHR0cDovL3d3dy5qZnVzaW9uLm9yZy8="/> <input type="hidden"name="b90bc837e46d358fa4701cfdd3c82e3a"value="1"/> form>
As you can see the name of this form is login, so you have to set the loginform_id to “login”.
The id’s for the username and password fields are username and passwd. Because these contain name and pass the cURL routines will find them without problems. You need to set the input_username_id and input_password_id parameters if you have something totally different. Integrations that use the emailaddress as identification often have email in the id’s. In this case you will see that the defaults are already changed to adopt to this setup.
The action parameter is a full URL so the relpath parameter should be set to no.
The cURL routines will find the button and hidden fields, analyse them and use them to login in exactly the same way a human user would do. For special cases like backward dual login (there are plugins and core hacks to make it possible to also login from Moodle and Magento to all integrations automatically) we can override the value of a hidden field by using the parameter override. For reverse duallogin we use the value login[indirect]=no. So if the login form has a hidden field with the name login[indirect] the value will be set to no independent of the real value put in the form. You can have multiple overrides by separating them with a comma.
If hidden and button information should be used to login we can set the hidden and buttons parameter. This really depends on the way login is processed by the integration. Leave it to yes for a start. If anything else fails and you still cannot login, try setting these values to no.
Step 3. Login and observe cookies
The routines now submit the loginform. The integration software will now, if the login is successful try to set cookies on the clients system to start a fresh session. The Curl routines will intercept these cookies, analyze them, modify them if needed and then set those cookies by themselves.
You can make them change the cookie domain, cookie path, expiration time, secure flag and http flag by setting the parameters Cookie Domain, Cookie path, cookie_expires, secure and httponly. If your integrated software has the cookie domain and cookie path set (use .mydomain.com and note the dot in front) then there is no need to set those parameters. The routines will figure this out themselves. However, if you cannot set the domain and path in the integrated software the software or your browser will come up with something. Sometimes weird domains like .www.mydomain.com (note the dot!). You now have to set the cookie_domain parameter to exactly the same as the cookie properties. You can find this out as follows:
1. Install the Firefox browser
2. Install the Firebug plugin in this browser
3. Install the Firecookie plugin for Firebug
You can now see what cookies are set. So
1. Clear all cookies
2. Go to the integrated software and login
3. Note what cookies are set
Now logout the integrated software, enable your JFusion plugin and
1. Clear all cookies
2. Log in from Joomla.
You will now be able to see what cookies are set by Joomla and the plugin. Change the plugin cookie parameters to match exactly the original properties. Note that the expiration time will be set for the session cookie, so it will no longer be listed as “session” but will show an expiration time.
So far so good. We are now logged in. That leaves us with the logout procedure.
Step 4. Logout.
Actually we logout by starting another session and deleting all cookies that the integration tries to set. This is not very elegant but it is very effective. The procedure taken by the curl toutines is simple, start another session and intercept the cookies that the integration tries to set. Then just delete them, except for cookies specified with the parameter leavealone. These are special cookies for the integration and cookies used for a “remember me” option. An example is the MOODLEID_ cookie that contains the session status (the encrypted username; nobody when a session is finished). To retain this cookie you set this parameter to MOODLE_ID⇒. The greater than character tells the cURL routines to leave this cookie alone only when the expiration time is greater than the current (server!) time. You can separate different cookies with a comma. There are more options available:
Specify the cookies with name=value, name2=value2 etc.
If ‘name’ is an existing cookie name then that cookie will be effected depending on the value: If value = '>' then the 'name' cookies with an expiration date/time > now() will not be deleted If value = '0' then the 'name' cookies will never be deleted at all
If ‘name’ = '0' then all cookies will be affected according to the value thus
0 = > will keep all cookies that are not session cookies 0 = 0 will keep all cookies We leave the parameter logout_url empty.
Plugin specific configuration
Magento
1. In system/configuration/web/session cookie management set the cookie properties exactly as those in your Magento Jfusion plugin parameters
2. In system/configuration/web/session validation settings set validate REMOTE_ADDR to no
Moodle
1. In sitemaintenance session handlingset the cookie properties exactly as those in your Moodle Jfusion plugin parameters
Joomla_ext
1. Joomla has no way of setting cookie properties so you have to install a second Joomla in a subdirectory and observe the domain and path properties set by your webbrowser. See above.
Default Parameters
| Parameter | Magento | Moodle | Joomla_ext |
| Cookie domain | |||
| Cookie path | |||
| Cookie expires | 1800 | 1800 | 1800 |
| Cookie secure | No | No | No |
| Cookie httponly | No | No | No |
| Override | login[indirect]=no | login[indirect]=no | |
| Leavealone | magento⇒ | MOODLEID_⇒ | |
| Integrationtype | 1 | 1 | 0 |
| Relpath | No | Yes | No |
| Hidden | Yes | No | Yes |
| Buttons | Yes | Yes | Yes |
| Login_Url | index.php/customer/account/login/ | login/ | / |
| Loginform_id | login-form | login | login |
| Input_username_id | |||
| Input_password_id | |||
| Logout_url | |||
My installation:
| Parameter | |||
| Cookie domain | |||
| Cookie path | |||
| Cookie expires | |||
| Cookie secure | |||
| Cookie httponly | |||
| Override | |||
| Leavealone | |||
| Integrationtype | |||
| Relpath | |||
| Hidden | |||
| Buttons | |||
| Login_Url | |||
| Loginform_id | |||
| Input_username_id | |||
| Input_password_id | |||
| Logout_url | |||
Parameter overview
| Parameter | Description |
| Login Identifier | In order to be able to integrate software that identifies a user with it’s email address (especially when this integration is the master) you can choose here what a user should type here. Note that when you use a username Jfusion will login to email-only software with the email address automatically |
| Login URL | This the relative path to a page with a login form of thge integration. This path is added to the “full URL to integrated software” parameter |
| Login form ID | ID or name of the login form. You can find this by displaying the page source of the login page |
| Input username ID | The ID or name of the input used for the username (or email address when used to login). Can be left empty for standard login forms |
| Input password ID | The same as above, but for the password input |
| Logout URL | Can be left empty |
| Cookie domain | The routines are smart enough to find this out, so only play with this when you have problems and know what you do |
| Cookie path | See above |
| Cookie expires | The lifetime of a cookie in seconds. Please make sure that all cookies (Joomla and all integrations) have the same lifetime for cookies |
| Secure | Should we use a secure cookie. That depends on the settings in Joomla and integration software. If they use secure cookies, this should be set to yes |
| Httponly | See above |
| Override | This is a special field that makes it possible to override, eg set a different value for a cookie that the integration software wants to set. Used for a reversed dual login, like Magento en Moodle where you are allowed to login in the integration and in Joomla. Please note that you need special software to enable this, sometimes a core hack. Not part of JFusion Example: login[indirect]=no,redirect=/ |
| Leavealone | When logging out, the routines delete all cookies set by the integration by default. Specify cookies here for something like ‘remember me’ cookies. You will see a default here when we know about such cookies. The form is COOKIE=0 when a non session cookie must be kept. Seperate cookies with a comma. Exampel: MOODLEID_=0 |
| Integrationtype | Do not change unless you are a developer. Currently 0 or 1 |
| Relpath | Specify of the actionpath of the loginform is absolute or relative to the base URL |
| Hidden | Should hidden fields posted on login? |
| Buttons | Should button information posted on login? |
Socket Error List
| Number | Reason |
| 0 | Success |
| 1 | Operation not permitted |
| 2 | No such file or directory |
| 3 | No such process |
| 4 | Interrupted system call |
| 5 | Input/output error |
| 6 | No such device or address |
| 7 | Argument list too long |
| 8 | Exec format error |
| 9 | Bad file descriptor |
| 10 | No child processes |
| 11 | Resource temporarily unavailable |
| 12 | Cannot allocate memory |
| 13 | Permission denied |
| 14 | Bad address |
| 15 | Block device required |
| 16 | Device or resource busy |
| 17 | File exists |
| 18 | Invalid cross-device link |
| 19 | No such device |
| 20 | Not a directory |
| 21 | Is a directory |
| 22 | Invalid argument |
| 23 | Too many open files in system |
| 24 | Too many open files |
| 25 | Inappropriate ioctl for device |
| 26 | Text file busy |
| 27 | File too large |
| 28 | No space left on device |
| 29 | Illegal seek |
| 30 | Read-only file system |
| 31 | Too many links |
| 32 | Broken pipe |
| 33 | Numerical argument out of domain |
| 34 | Numerical result out of range |
| 35 | Resource deadlock avoided |
| 36 | File name too long |
| 37 | No locks available |
| 38 | Function not implemented |
| 39 | Directory not empty |
| 40 | Too many levels of symbolic links |
| 41 | Unknown error 41 |
| 42 | No message of desired type |
| 43 | Identifier removed |
| 44 | Channel number out of range |
| 45 | Level 2 not synchronized |
| 46 | Level 3 halted |
| 47 | Level 3 reset |
| 48 | Link number out of range |
| 49 | Protocol driver not attached |
| 50 | No CSI structure available |
| 51 | Level 2 halted |
| 52 | Invalid exchange |
| 53 | Invalid request descriptor |
| 54 | Exchange full |
| 55 | No anode |
| 56 | Invalid request code |
| 57 | Invalid slot |
| 58 | Unknown error 58 |
| 59 | Bad font file format |
| 60 | Device not a stream |
| 61 | No data available |
| 62 | Timer expired |
| 63 | Out of streams resources |
| 64 | Machine is not on the network |
| 65 | Package not installed |
| 66 | Object is remote |
| 67 | Link has been severed |
| 68 | Advertise error |
| 69 | Srmount error |
| 70 | Communication error on send |
| 71 | Protocol error |
| 72 | Multihop attempted |
| 73 | RFS specific error |
| 74 | Bad message |
| 75 | Value too large for defined data type |
| 76 | Name not unique on network |
| 77 | File descriptor in bad state |
| 78 | Remote address changed |
| 79 | Can not access a needed shared library |
| 80 | Accessing a corrupted shared library |
| 81 | .lib section in a.out corrupted |
| 82 | Attempting to link in too many shared libraries |
| 83 | Cannot exec a shared library directly |
| 84 | Invalid or incomplete multibyte or wide character |
| 85 | Interrupted system call should be restarted |
| 86 | Streams pipe error |
| 87 | Too many users |
| 88 | Socket operation on non-socket |
| 89 | Destination address required |
| 90 | Message too long |
| 91 | Protocol wrong type for socket |
| 92 | Protocol not available |
| 93 | Protocol not supported |
| 94 | Socket type not supported |
| 95 | Operation not supported |
| 96 | Protocol family not supported |
| 97 | Address family not supported by protocol |
| 98 | Address already in use |
| 99 | Cannot assign requested address |
| 100 | Network is down |
| 101 | Network is unreachable |
| 102 | Network dropped connection on reset |
| 103 | Software caused connection abort |
| 104 | Connection reset by peer |
| 105 | No buffer space available |
| 106 | Transport endpoint is already connected |
| 107 | Transport endpoint is not connected |
| 108 | Cannot send after transport endpoint shutdown |
| 109 | Too many references: cannot splice |
| 110 | Connection timed out |
| 111 | Connection refused |
| 112 | Host is down |
| 113 | No route to host |
| 114 | Operation already in progress |
| 115 | Operation now in progress |
| 116 | Stale NFS file handle |
| 117 | Structure needs cleaning |
| 118 | Not a XENIX named type file |
| 119 | No XENIX semaphores available |
| 120 | Is a named type file |
| 121 | Remote I/O error |
| 122 | Disk quota exceeded |
| 123 | No medium found |
| 124 | Wrong medium type |
