0
我在我的應用程序上有一個經過身份驗證的部分,但身份驗證通過oauth完成到第三方服務。我得到的200回叫服務,現在我創建/找到我的用戶,並把他作爲登錄如何序列化用戶認證?
所以我的供應商是:
providers:
users:
entity: { class: MainBundle:User, property: id }
我的用戶實現安全的的UserInterface,雖然我不在我的用戶實體上擁有用戶名,密碼等屬性。我認爲這個id是我可以使用的唯一標識符。
我的標記設置如下:
$token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles());
$this->securityContext->setToken($token);
我要做到這一點,而不使用JMS包現在;我的序列化看起來像這樣:
/**
* Serialize
* @return string|void
*/
public function serialize()
{
return serialize(array(
'id' => $this->getId(),
'display_name' => $this->getDisplayName(),
'email' => $this->getEmail(),
));
}
/**
* Unserialize
* @return mixed|void
*/
public function unserialize($data)
{
$data = unserialize($data);
$this->setId($data['id']);
$this->setDisplayName($data['display_name']);
$this->setEmail($data['email']);
return $this;
}
使用上面我得到一個無限循環重定向。
起初我只序列化了id,但是用戶的所有其他屬性都不可用。
然後我試圖整個對象序列化($這一點),但給我的1000
一個Xdebug的嵌套級別的錯誤我有點失去了如何使這項工作的認證與序列化
在Symfony2中,「JMSSerializerBundle」通常用於序列化實體。你看過嗎? – tolgap