Skip to content

Commit

Permalink
style patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Redjik committed Sep 17, 2015
1 parent 9d0e8f8 commit e61f702
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 34 deletions.
22 changes: 15 additions & 7 deletions api/src/Auth/Blacklist/Blacklist.php
@@ -1,14 +1,22 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

/**
* Created by PhpStorm.
* User: ivanmatveev
* Date: 17.09.15
* Time: 20:27
* Time: 20:27.
*/

namespace Spira\Auth\Blacklist;


use Carbon\Carbon;
use Spira\Auth\Token\TokenExpiredException;

Expand Down Expand Up @@ -40,7 +48,7 @@ public function __construct(StorageInterface $driver, $key, $exp = null)
public function add($payload)
{
$seconds = null;
if ($this->exp && isset($payload[$this->exp])){
if ($this->exp && isset($payload[$this->exp])) {
$exp = Carbon::createFromTimeStampUTC($payload['exp']);
if ($exp->isPast()) {
return;
Expand All @@ -49,23 +57,23 @@ public function add($payload)
$seconds = $exp->diffInSeconds(Carbon::now()->subSecond(10));
}

if (isset($payload[$this->key])){
if (isset($payload[$this->key])) {
$this->driver->add($payload[$this->key], $seconds);
}
}

/**
* Checks if token in a blacklist
* 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])){
if (isset($payload[$this->key]) && $this->driver->get($payload[$this->key])) {
throw new TokenExpiredException;
}

return false;
}
}
}
22 changes: 14 additions & 8 deletions api/src/Auth/Blacklist/CacheDriver.php
@@ -1,27 +1,33 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

/**
* Created by PhpStorm.
* User: ivanmatveev
* Date: 17.09.15
* Time: 20:42
* 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;
}

Expand All @@ -32,11 +38,11 @@ public function __construct(Repository $cache)
*/
public function add($id, $seconds = null)
{
if ($seconds = null){
$seconds = 60*60;
if ($seconds = null) {
$seconds = 60 * 60;
}

$this->cache->add($id,$id,ceil($seconds/60));
$this->cache->add($id, $id, ceil($seconds / 60));
}

/**
Expand All @@ -47,4 +53,4 @@ public function get($id)
{
return $this->cache->get($id);
}
}
}
14 changes: 11 additions & 3 deletions api/src/Auth/Blacklist/StorageInterface.php
@@ -1,14 +1,22 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

/**
* Created by PhpStorm.
* User: ivanmatveev
* Date: 17.09.15
* Time: 20:29
* Time: 20:29.
*/

namespace Spira\Auth\Blacklist;


interface StorageInterface
{
/**
Expand All @@ -23,4 +31,4 @@ public function add($id, $seconds = null);
* @return mixed
*/
public function get($id);
}
}
7 changes: 3 additions & 4 deletions api/src/Auth/Driver/Guard.php
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/


namespace Spira\Auth\Driver;

use Illuminate\Contracts\Auth\Authenticatable;
Expand All @@ -19,7 +18,6 @@
use Spira\Auth\Payload\PayloadValidationFactory;
use Spira\Auth\Token\JWTInterface;
use Spira\Auth\Token\RequestParser;
use Spira\Auth\Token\TokenExpiredException;
use Spira\Contract\Exception\NotImplementedException;

class Guard implements \Illuminate\Contracts\Auth\Guard
Expand Down Expand Up @@ -303,10 +301,11 @@ public function viaToken()
*/
public function logout()
{
try{
try {
$token = $this->getTokenFromRequest();
$this->blacklist->add($this->getTokenizer()->decode($token));
}catch (\Exception $e){}
} catch (\Exception $e) {
}
$this->user = false;
}

Expand Down
3 changes: 1 addition & 2 deletions api/src/Auth/Payload/PayloadValidationFactory.php
Expand Up @@ -13,8 +13,7 @@
use Spira\Auth\Token\TokenInvalidException;

/**
* Class PayloadValidationFactory
* @package Spira\Auth\Payload
* Class PayloadValidationFactory.
*/
class PayloadValidationFactory
{
Expand Down
12 changes: 6 additions & 6 deletions api/src/Auth/Providers/JWTAuthDriverServiceProvider.php
Expand Up @@ -173,7 +173,7 @@ protected function registerTokenizer()

/**
* Base payload factory
* Rules can be overridden in
* Rules can be overridden in.
* @see getPayloadGenerators
*/
protected function registerPayloadFactory()
Expand All @@ -185,7 +185,7 @@ protected function registerPayloadFactory()

/**
* Base payload validator factory
* Rules can be overridden in
* Rules can be overridden in.
* @see getValidationRules
*/
protected function registerPayloadValidatorFactory()
Expand Down Expand Up @@ -250,7 +250,7 @@ protected function getPayloadGenerators()
}

/**
* Validation rules for payload
* Validation rules for payload.
* @return array
*/
protected function getValidationRules()
Expand Down Expand Up @@ -299,17 +299,17 @@ abstract protected function getSecretPrivate();

/**
* Needed for token invalidation during logout
* Optional
* Optional.
*/
protected function registerBlackList()
{
$this->app->bind(Blacklist::class, function ($app) {
return new Blacklist($this->app[StorageInterface::class],$this->tokenKey, $this->tokenExp);
return new Blacklist($this->app[StorageInterface::class], $this->tokenKey, $this->tokenExp);
});
}

/**
* Driver used to store invalid tokens
* Driver used to store invalid tokens.
*/
protected function registerBlackListDriver()
{
Expand Down
1 change: 0 additions & 1 deletion api/src/Auth/Token/TokenExpiredException.php
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/


namespace Spira\Auth\Token;

use Exception;
Expand Down
1 change: 0 additions & 1 deletion api/src/Contract/Exception/ForbiddenException.php
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/


namespace Spira\Contract\Exception;

use Exception;
Expand Down
1 change: 0 additions & 1 deletion api/src/Contract/Exception/NotImplementedException.php
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/


namespace Spira\Contract\Exception;

use Exception;
Expand Down
1 change: 0 additions & 1 deletion api/src/Contract/Exception/UnauthorizedException.php
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/


namespace Spira\Contract\Exception;

use Exception;
Expand Down

0 comments on commit e61f702

Please sign in to comment.