When a user logs into Drupal with hybridauth, the old session data is loaded from the database and merged with the newest session information. But the data from the current session isn't written to storage until the user logs out.
This is a problem if a service wants to load information about a user's session or auth tokens. They would get the old tokens which have expired.
I would suggest that the hook_user_login() be modified so that right after we restore the session, we save that new session information to the database.
/**
* Implements hook_user_login().
*/
function hybridauth_user_login(&$edit, $account) {
if ($hybridauth_session_data = _hybridauth_session_load_by_uid($account->uid)) {
if ($hybridauth = hybridauth_get_instance()) {
if (is_object($hybridauth)) {
$hybridauth_session_data = $hybridauth_session_data['data'];
$hybridauth_session_data_current = unserialize($hybridauth->getSessionData());
if (is_array($hybridauth_session_data_current)) {
$hybridauth_session_data = serialize(array_merge(unserialize($hybridauth_session_data), $hybridauth_session_data_current));
}
// Call Hybrid_Auth::restoreSessionData() to set stored data.
$hybridauth->restoreSessionData($hybridauth_session_data);
}
}
}
}
to
/**
* Implements hook_user_login().
*/
function hybridauth_user_login(&$edit, $account) {
if ($hybridauth_session_data = _hybridauth_session_load_by_uid($account->uid)) {
if ($hybridauth = hybridauth_get_instance()) {
if (is_object($hybridauth)) {
$hybridauth_session_data = $hybridauth_session_data['data'];
$hybridauth_session_data_current = unserialize($hybridauth->getSessionData());
if (is_array($hybridauth_session_data_current)) {
$hybridauth_session_data = serialize(array_merge(unserialize($hybridauth_session_data), $hybridauth_session_data_current));
}
// Call Hybrid_Auth::restoreSessionData() to set stored data.
$hybridauth->restoreSessionData($hybridauth_session_data);
_hybridauth_session_save($hybridauth_session_data, $account->uid);
}
}
}
}
This pattern also follows the example session handling documentation for hybridauth itself.
http://hybridauth.sourceforge.net/userguide/HybridAuth_Sessions.html
Note that when creating a session, they immediately store that information as well.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2626624-session.patch | 447 bytes | minoroffense |
Comments
Comment #2
minoroffense commentedHere's a patch with the suggested changes
Comment #4
duozerskMathew,
Thank you for using the module and for the patch.
Committed!
There might also be some other places to refresh the session info... like when the user adds new identity to their account; and may be smth else.
Thanks
AndyB