Skip to content

Commit

Permalink
Merge 81e9018 into 0f0ffa3
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Sep 25, 2015
2 parents 0f0ffa3 + 81e9018 commit 8edaea2
Show file tree
Hide file tree
Showing 142 changed files with 4,185 additions and 2,632 deletions.
1 change: 1 addition & 0 deletions api/.env
Expand Up @@ -17,6 +17,7 @@ WEBSERVER_HOST={$WEB_PORT_8080_TCP_ADDR}
WEBSERVER_PORT=8080

AUTH_MODEL=App\Models\User
AUTH_DRIVER=jwt

DB_CONNECTION=pgsql
DB_HOST={$DATABASE_PORT_5432_TCP_ADDR}
Expand Down
1 change: 1 addition & 0 deletions api/.travis.env
Expand Up @@ -15,6 +15,7 @@ WEBSERVER_HOST=127.0.0.1
WEBSERVER_PORT=8000

AUTH_MODEL=App\Models\User
AUTH_DRIVER=jwt

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
Expand Down
6 changes: 5 additions & 1 deletion api/app/Console/Commands/ApiaryValidateCommand.php
Expand Up @@ -55,6 +55,10 @@ public function handle()

$fs->put($fileLocation, $apib);

return 0;
$validator = base_path().'/node_modules/.bin/api-blueprint-validator';

exec("$validator $fileLocation", $output, $exitCode);

return $exitCode;
}
}
12 changes: 5 additions & 7 deletions api/app/Exceptions/NotImplementedException.php
Expand Up @@ -12,20 +12,18 @@

use Exception;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

class NotImplementedException extends HttpException
class NotImplementedException extends \Spira\Contract\Exception\NotImplementedException
{
/**
* Create a new Not Implemented exception instance.
*
* @param string $message
* @param int $code
* @param Exception $previous
* @return void
* @param string $message
* @param int $code
* @param Exception $previous
*/
public function __construct($message = 'Not Implemented.', $code = 0, Exception $previous = null)
{
parent::__construct(Response::HTTP_NOT_IMPLEMENTED, $message, $previous);
parent::__construct($message, Response::HTTP_NOT_IMPLEMENTED, $previous);
}
}
6 changes: 2 additions & 4 deletions api/app/Exceptions/UnauthorizedException.php
Expand Up @@ -19,11 +19,9 @@ class UnauthorizedException extends HttpException
/**
* Create a new Unauthorized exception instance.
*
* @param string $message
* @param int $code
* @param string $message
* @param int $code
* @param \Exception $previous
*
* @return void
*/
public function __construct($message = 'Unauthorized.', $code = 0, Exception $previous = null)
{
Expand Down
92 changes: 92 additions & 0 deletions api/app/Extensions/Controller/AuthorizesRequestsTrait.php
@@ -0,0 +1,92 @@
<?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.
*/

namespace App\Extensions\Controller;

use Spira\Auth\Access\Gate;
use Spira\Contract\Exception\ForbiddenException;

trait AuthorizesRequestsTrait
{
/**
* Authorize a given action against a set of arguments.
*
* @param mixed $ability
* @param mixed|array $arguments
* @return void
*
* @throws ForbiddenException
*/
public function authorize($ability, $arguments = [])
{
list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);

if (! $this->getGate()->check($ability, $arguments)) {
throw $this->createGateUnauthorizedException($ability, $arguments);
}
}

/**
* Authorize a given action for a user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
* @param mixed $ability
* @param mixed|array $arguments
* @return void
*
* @throws ForbiddenException
*/
public function authorizeForUser($user, $ability, $arguments = [])
{
list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);

$result = $this->getGate()->forUser($user)->check($ability, $arguments);

if (! $result) {
throw $this->createGateUnauthorizedException($ability, $arguments);
}
}

/**
* Guesses the ability's name if it wasn't provided.
*
* @param mixed $ability
* @param mixed|array $arguments
* @return array
*/
protected function parseAbilityAndArguments($ability, $arguments)
{
if (is_string($ability)) {
return [$ability, $arguments];
}

return [debug_backtrace(false, 3)[2]['function'], $ability];
}

/**
* @return Gate
*/
public function getGate()
{
return app(Gate::GATE_NAME);
}

/**
* Throw an unauthorized exception based on gate results.
*
* @param string $ability
* @param array $arguments
* @return ForbiddenException
*/
protected function createGateUnauthorizedException($ability, $arguments)
{
return new ForbiddenException();
}
}
58 changes: 0 additions & 58 deletions api/app/Extensions/JWTAuth/ClaimFactory.php

This file was deleted.

116 changes: 0 additions & 116 deletions api/app/Extensions/JWTAuth/JWTAuth.php

This file was deleted.

42 changes: 0 additions & 42 deletions api/app/Extensions/JWTAuth/JWTManager.php

This file was deleted.

0 comments on commit 8edaea2

Please sign in to comment.