Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
travis fix
- Loading branch information
Showing
10 changed files
with
264 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: ivanmatveev | ||
* Date: 17.09.15 | ||
* Time: 20:27 | ||
*/ | ||
|
||
namespace Spira\Auth\Blacklist; | ||
|
||
|
||
use Carbon\Carbon; | ||
use Spira\Auth\Token\TokenExpiredException; | ||
|
||
class Blacklist | ||
{ | ||
private $key; | ||
/** | ||
* @var StorageInterface | ||
*/ | ||
private $driver; | ||
private $exp; | ||
|
||
/** | ||
* @param StorageInterface $driver | ||
* @param string $key key of the token id in the payload | ||
* @param string|null $exp key of the exp inside payload | ||
*/ | ||
public function __construct(StorageInterface $driver, $key, $exp = null) | ||
{ | ||
$this->key = $key; | ||
$this->driver = $driver; | ||
$this->exp = $exp; | ||
} | ||
|
||
/** | ||
* @param $payload | ||
* @return void | ||
*/ | ||
public function add($payload) | ||
{ | ||
if ($this->exp && isset($payload[$this->exp])){ | ||
$exp = Carbon::createFromTimeStampUTC($payload['exp']); | ||
if ($exp->isPast()) { | ||
return; | ||
} | ||
|
||
$seconds = $exp->diffInSeconds(Carbon::now()->subSecond(10)); | ||
|
||
if (isset($payload[$this->key])){ | ||
$this->driver->add($payload[$this->key], $seconds); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Checks if token in a blacklist | ||
* @param $payload | ||
* @return bool | ||
* @throw TokenExpiredException | ||
*/ | ||
public function check($payload) | ||
{ | ||
if (isset($payload[$this->key]) && $this->driver->get($payload[$this->key])){ | ||
throw new TokenExpiredException; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: ivanmatveev | ||
* Date: 17.09.15 | ||
* Time: 20:42 | ||
*/ | ||
|
||
namespace Spira\Auth\Blacklist; | ||
|
||
|
||
use Illuminate\Contracts\Cache\Repository; | ||
|
||
class CacheDriver implements StorageInterface | ||
{ | ||
|
||
/** | ||
* @var Repository | ||
*/ | ||
private $cache; | ||
|
||
public function __construct(Repository $cache) | ||
{ | ||
|
||
$this->cache = $cache; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @param $seconds | ||
* @return mixed | ||
*/ | ||
public function add($id, $seconds) | ||
{ | ||
$this->cache->add($id,$id,ceil($seconds/60)); | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @return mixed | ||
*/ | ||
public function get($id) | ||
{ | ||
return $this->cache->get($id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: ivanmatveev | ||
* Date: 17.09.15 | ||
* Time: 20:29 | ||
*/ | ||
|
||
namespace Spira\Auth\Blacklist; | ||
|
||
|
||
interface StorageInterface | ||
{ | ||
/** | ||
* @param $id | ||
* @param $seconds | ||
* @return mixed | ||
*/ | ||
public function add($id, $seconds); | ||
|
||
/** | ||
* @param $id | ||
* @return mixed | ||
*/ | ||
public function get($id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.