25 $this->
root=
'/'.\trim($root,
'/').
'/';
51 $data=[
'platform'=>$data[
'platform']??
'',
'browser'=>$data[
'browser']??
'',
'ip'=>$data[
'ip']??
''];
52 return \md5(\json_encode($data));
61 $token = $this->tokenGenerator ();
62 }
while ( $this->exists($token) );
70 protected function getKey(
string $token):string{
71 return self::CACHE_KEY.($this->root).$token;
78 public function exists(
string $token):bool{
79 return
CacheManager::$cache->exists($this->getKey($token));
86 public function expired(
string $token):bool{
87 $tokenKey=$this->getKey($token);
88 $expired= CacheManager::$cache->expired($tokenKey,$this->duration);
90 CacheManager::$cache->remove($tokenKey);
102 public function store(array $data):string{
103 if($this->sameOrigin){
104 $data[
'origin']=$this->getOrigin();
106 $token=$this->generateToken();
107 CacheManager::$cache->store($this->getKey($token),$data);
116 public function remove(
string $token){
117 CacheManager::$cache->remove($this->getKey($token));
127 $tokenKey=$this->getKey($token);
128 if(CacheManager::$cache->exists($tokenKey) && !CacheManager::$cache->expired($tokenKey,$this->duration)) {
129 $data= CacheManager::$cache->fetch($tokenKey);
130 if(!$this->sameOrigin || $this->isSameOrigin($data)){
142 return ($data[
'origin']??
'')===$this->getOrigin();
149 $this->length = $length;
156 $this->duration = $duration;
163 $this->sameOrigin = $sameOrigin;
166 public function setParams(
int $length,
int $duration,
bool $sameOrigin){
167 $this->length=$length;
168 $this->duration=$duration;
169 $this->sameOrigin=$sameOrigin;
Manager for caches (Router, Rest, models).
setSameOrigin(bool $sameOrigin)
generateOrigin(array $data)
store(array $data)
Stores some data associated to a new token.
setDuration(int $duration)
setParams(int $length, int $duration, bool $sameOrigin)
__construct(string $root, int $length=10, int $duration=3600, bool $sameOrigin=false)
AuthTokens constructor.
fetch($token)
Gets the data associated to a token.