cURL Dual Login

By Henk Wevers (www.breincoach.com)

At this time the following plugins use the cURL mechanism for Dual Login;

  1. Magento
  2. Moodle
  3. Joomla_ext
  4. SMF
  5. DokuWiki
  6. osCommerse (2.x and 3.x)
  7. xtCommerce (3.x)
  8. 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
Overridelogin[indirect]=nologin[indirect]=no
Leavealone magento⇒ MOODLEID_⇒
Integrationtype110
Relpath No Yes No
Hidden Yes No Yes
Buttons Yes Yes Yes
Login_Urlindex.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 IDID or name of the login form. You can find this by displaying the page source of the login page
Input username IDThe 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 IDThe same as above, but for the password input
Logout URLCan be left empty
Cookie domainThe routines are smart enough to find this out, so only play with this when you have problems and know what you do
Cookie pathSee above
Cookie expiresThe lifetime of a cookie in seconds. Please make sure that all cookies (Joomla and all integrations) have the same lifetime for cookies
SecureShould 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
HttponlySee above
OverrideThis 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=/
LeavealoneWhen 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
IntegrationtypeDo not change unless you are a developer. Currently 0 or 1
RelpathSpecify of the actionpath of the loginform is absolute or relative to the base URL
HiddenShould hidden fields posted on login?
ButtonsShould button information posted on login?

Socket Error List

NumberReason
0Success
1Operation not permitted
2No such file or directory
3No such process
4Interrupted system call
5Input/output error
6No such device or address
7Argument list too long
8Exec format error
9Bad file descriptor
10No child processes
11Resource temporarily unavailable
12Cannot allocate memory
13Permission denied
14Bad address
15Block device required
16Device or resource busy
17File exists
18Invalid cross-device link
19No such device
20Not a directory
21Is a directory
22Invalid argument
23Too many open files in system
24Too many open files
25Inappropriate ioctl for device
26Text file busy
27File too large
28No space left on device
29Illegal seek
30Read-only file system
31Too many links
32Broken pipe
33Numerical argument out of domain
34Numerical result out of range
35Resource deadlock avoided
36File name too long
37No locks available
38Function not implemented
39Directory not empty
40Too many levels of symbolic links
41Unknown error 41
42No message of desired type
43Identifier removed
44Channel number out of range
45Level 2 not synchronized
46Level 3 halted
47Level 3 reset
48Link number out of range
49Protocol driver not attached
50No CSI structure available
51Level 2 halted
52Invalid exchange
53Invalid request descriptor
54Exchange full
55No anode
56Invalid request code
57Invalid slot
58Unknown error 58
59Bad font file format
60Device not a stream
61No data available
62Timer expired
63Out of streams resources
64Machine is not on the network
65Package not installed
66Object is remote
67Link has been severed
68Advertise error
69Srmount error
70Communication error on send
71Protocol error
72Multihop attempted
73RFS specific error
74Bad message
75Value too large for defined data type
76Name not unique on network
77File descriptor in bad state
78Remote address changed
79Can not access a needed shared library
80Accessing a corrupted shared library
81.lib section in a.out corrupted
82Attempting to link in too many shared libraries
83Cannot exec a shared library directly
84Invalid or incomplete multibyte or wide character
85Interrupted system call should be restarted
86Streams pipe error
87Too many users
88Socket operation on non-socket
89Destination address required
90Message too long
91Protocol wrong type for socket
92Protocol not available
93Protocol not supported
94Socket type not supported
95Operation not supported
96Protocol family not supported
97Address family not supported by protocol
98Address already in use
99Cannot assign requested address
100Network is down
101Network is unreachable
102Network dropped connection on reset
103Software caused connection abort
104Connection reset by peer
105No buffer space available
106Transport endpoint is already connected
107Transport endpoint is not connected
108Cannot send after transport endpoint shutdown
109Too many references: cannot splice
110Connection timed out
111Connection refused
112Host is down
113No route to host
114Operation already in progress
115Operation now in progress
116Stale NFS file handle
117Structure needs cleaning
118Not a XENIX named type file
119No XENIX semaphores available
120Is a named type file
121Remote I/O error
122Disk quota exceeded
123No medium found
124Wrong medium type
technical/curl_dual_login.txt · Last modified: 2010/12/25 19:34 by james
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki