Sunday, May 3, 2009

symfony sfGuard and sfRemember

I needed to have sfGuard to have a rememberme feature valid for cross-subdomain. It appears that the plugin doesnt allow to configure this. So here is the snippet to workaround this limitation. to add just after your $user->signin().
$cookie_name = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember');
$response = sfContext::getInstance()->getResponse();
$cookies = $response->getCookies();
// create an alias to ease readability
$cookie = $cookies[$cookie_name];
// override the cookie domain to make it valid for cross-subdomain
$cookie['domain'] = ".".$cookie['domain'];
// set the cookie back
$response->setCookie($cookie['name'], $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);

0 comments:

Share/Save/Bookmark