Active
Project:
Token authentication
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Dec 2012 at 12:02 UTC
Updated:
19 Dec 2012 at 07:59 UTC
Nice module but I am having a difficulty with it. I have actually created a browser extension that repeatedly hits (after every five seconds) the URLs using http POST request. These URLs are only accessible to authenticated users so I am also posting the authentication token with the post request. Now the problem is, when the extension is running, login using open id does not work. After disabling token authentication, it works perfectly.
I know that this scenario is a bit unique but can the maintainers give me some hint, why it is happening. I am also looking into the code
Not sure
Comments
Comment #1
qasimzee commentedAfter commenting out complete "hook_exit()", things started working fine. Can there be any side effects of this ?
Secondly, is it a good idea to make user anonymous after every request? I am talking about
$user = drupal_anonymous_user();undertokenauth_exit()Comment #2
qasimzee commentedping
Comment #3
Grayside commentedIt makes no sense to me that hook_exit() can be causing this. The code there is to make sure the user is reverted to anonymous, instead of allowing the existing user from persisting. It was at least in the passed a necessary step to make sure there were no security holes, though could now be deprecated.
OpenID colliding with Tokenauth I would think caused by tokenauth's use of "token" as the querystring parameter. This can be changed as a variable to something more sane, such as "tokenauth".
Comment #4
qasimzee commentedI am debugging this issue since last week. I totally agree that hook_exit might not be the basic cause of this issue. Secondly, it seems to me that removing hook_exit will not be the solution. As when I removed it, the login works but it logs in the user that is associated with the token, not the new user. After some more investigation, I realized that open id successfully submits the
user_login_submitform and$user->uidhas the expected value but when I dblogged$user->uidintokenauth_menu_get_item_alter, it is still 0. Please note that I am sending tokenized AJAX calls in the background code of the browser extension after every 5 seconds and this issue is really driving me crazy. Any suggestions?Comment #5
Grayside commentedI did some quick checking, and I have a theory. On line 110 of tokenauth.module, we use
drupal_save_session(FALSE)to prevent a new session from being generated for the user. This is not necessarily an expected condition (authenticated user without a session) so I can imagine problems from this.Is there code in the OpenID module that checks for user session, and takes action if one is not found?
To test if this is the problem, simply comment out that one line and see if things work better. Note that without that line, anything that creates a fatal error before tokenauth_exit() is called will result in the "token-authenticated" user having an ongoing session and remain the active user.
Comment #6
qasimzee commenteddrupal_save_session(FALSE)seems really intelligent but I think removing it might create a security issue, if for example, I am sending tokenized requests, it might automatically logs in the user with that token. I did some more debugging in last few hours and it seems like session gets initiated by openid usinguser_login_submitbut in the mean time, $user becomes anonymous by the extension's tokenized call. Is it a good idea to useunset($_SESSION['tokenauth_auth'])inside hook_exit before$user = drupal_anonymous_user();, just to make sure that if there is some other request in between other than tokenized request, hook_exit don't make it anonymous.What do you suggest? Or is there a good way to test that whether the user was logged in using token or she was actually logged in using login form?
EDIT: I just updated hook_exit with the following code and things are working fine. Can you please suggest if it might have some side affect?
Comment #7
Grayside commentedSo. In #5 I am asking you to test the combination of Tokenauth + OpenID by seeing if it's the drupal_save_session() function causing the problem. I am not suggesting you run Tokenauth in production with *any* code commented out.
I will have to look closer at tokenauth_exit(). TBH I'm not sure when I'll get back to this. It could be a few days.
Comment #8
qasimzee commentedYeah, I have already tried it by commenting our
drupal_save_sessionbut the problem is it automatically logins the user whose token is being used by the extension.Comment #9
Grayside commentedAh, I see. Yes, I suppose that is expected behavior--since you can't login if you are still logged in as of the last session. However, if you leave hook_exit() as is, and maybe add `drupal_session_destroy_uid()` to kill the session? Our goal is to see if authenticated without a valid session is what is tripping up OpenID.