Recent I got a question how to connect my oAuth module to Tank Auth for user session management. While that might be possible, I think that would be overkill.
When I wrote the oAuth module, I also wrote a very simple module to handle the user session management. The module has only 3 methods:
Set the current user id
setId($userId, $rememberMe = false);
After your authentication process, being it oAuth or any thing else, use $this->current_user->setId(10, true); to set the current logged in user id to 10. The $rememberMe parameter defines if the user has to login or not the next time he or she visits the site.
For this functionality a cookie use used on the client side and a table named user_autologin on the server.
Get the current user id
Calling $userId = $this->current_user->getId(); will store the current logged in user in $userId or false if there is currently no active user session.
Log the current user off
To end a session use $this->current_user->logoff();.
For the Remember Me functionality to work you will need to create a table called user_autologin:
CREATE TABLE IF NOT EXISTS `user_autologin` ( `key_id` char(250) COLLATE utf8_bin NOT NULL, `user_id` int(11) NOT NULL DEFAULT '0', `user_agent` varchar(150) COLLATE utf8_bin NOT NULL, `last_ip` varchar(40) COLLATE utf8_bin NOT NULL, `last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`key_id`,`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
The code can be downloaded here. As always all feedback is welcome!