我正在使用带有自定义身份验证提供程序和mongodb持久用户的fosuserbundle。用户类具有一个属性,该属性保留为对另一个 mongodb 集合的引用集合,但此字段和其他字段未在安全令牌中序列化。在我的另一个项目中,用户作为一个普通的旧 php 对象被正确保存在令牌中并从中获取,所以我不明白问题是否是由于 mongodb 水合作用过度处理造成的。
通常,令牌中保留需要序列化的用户信息。fosuserbundle 将序列化属性:
/**
* Serializes the user.
*
* The serialized data have to contain the fields used by the equals method and the username.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id,
));
}
在"序列化"方法中定义。如果要序列化其他属性,则需要在 User 类中实现方法序列化/反序列化。这不是一个好的做法,因为当您从令牌中检索用户时,他通常会刷新。您是否在用户提供程序中实现了"刷新令牌"方法?