Jump to content


Photo

Setting up a Simple Single Sign On

api

  • Please log in to reply
1 reply to this topic

#1 jimf

jimf

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts

Posted 23 October 2012 - 03:57 PM

I have successfully created logins for all my users with the API, but I want my external application to be able to login to Zurmo so the users will have single sign in. I've added a simple block of code ot my module to do the sign on, and I've added the route to the beginrequest behavior, but I'm getting the following error when I try to execute my code.

session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent




This is in my DefaultController
   public function actionAutoLogin()
	    {
		  $identity=new UserIdentity('usa8965746', 'password');
   $identity->authenticate();
   if ($identity->errorCode == UserIdentity::ERROR_NONE)
   {
		   $duration= 3600*24*30; // 30 days
		   Yii::app()->user->login($identity,$duration);
		   $this->redirect("contacts");
   }
   else
   {
		  echo 'error';
   }
	    }

This is in BeginRequestBehavior
   protected $allowedGuestUserRoutes = array(
			    'zurmo/default/unsupportedBrowser',
			    'zurmo/default/login',
			 'bare/default/autologin',
			    'min/serve');

Stack Trace
#0
+  /Users/jim/sites/zurmo/yii/framework/web/CHttpSession.php(182): session_regenerate_id(true)
#1
+  /Users/jim/sites/zurmo/yii/framework/web/auth/CWebUser.php(700): CHttpSession->regenerateID(true)
#2
+  /Users/jim/sites/zurmo/yii/framework/web/auth/CWebUser.php(228): CWebUser->changeIdentity("usa8965746", "usa8965746", array("username" => "usa8965746"))
#3
&#8211;  /Users/jim/sites/zurmo/app/protected/modules/bare/controllers/DefaultController.php(272): CWebUser->login(UserIdentity, 2592000)
267			  $identity=new UserIdentity('usa8965746', 'password');
268			 $identity->authenticate();
269			 if ($identity->errorCode == UserIdentity::ERROR_NONE)
270			 {
271					 $duration= 3600*24*30; // 30 days
272					 Yii::app()->user->login($identity,$duration);
273					 $this->redirect("contacts");
274			 }
275			 else
276			 {
277				    echo 'error';
#4
+  /Users/jim/sites/zurmo/yii/framework/web/actions/CInlineAction.php(50): BareDefaultController->actionAutoLogin()


#2 Ivica

Ivica

    Advanced Member

  • Moderators
  • 478 posts

Posted 24 October 2012 - 12:13 PM

Jim, how do you manage cookies from your application?
Check WebUser::init method, I think the issue is because you have session already created in this method, and when you try to login user, it try to create session again.

So, to fix this issue, you probably need one more conditional, that will check if request is coming from your application, and have code similar to code for managing api request - check block: if (Yii::app()->apiRequest->isApiRequest())





Also tagged with one or more of these keywords: api

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users