-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petar Obradović
committed
Nov 28, 2018
0 parents
commit 9d0eac3
Showing
81 changed files
with
4,709 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# JetBrains | ||
.idea/ | ||
|
||
# Composer | ||
composer.lock | ||
vendor/ | ||
|
||
# PHP Coding Standards Fixer | ||
.php_cs | ||
.php_cs.cache | ||
|
||
# PHPUnit | ||
phpunit.xml | ||
|
||
# Tests | ||
Tests/.kernel/ |
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,38 @@ | ||
<?php | ||
use PhpCsFixer\Fixer\Import\OrderedImportsFixer; | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setUsingCache(true) | ||
->setRules([ | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'@DoctrineAnnotation' => true, | ||
'concat_space' => ['spacing' => 'one'], | ||
'array_syntax' => ['syntax' => 'short'], | ||
'list_syntax' => ['syntax' => 'short'], | ||
'phpdoc_align' => '', | ||
'phpdoc_no_empty_return' => false, | ||
'no_superfluous_phpdoc_tags' => true, | ||
'phpdoc_summary' => false, | ||
'ordered_imports' => [ | ||
'sortAlgorithm' => OrderedImportsFixer::SORT_ALPHA, | ||
'importsOrder' => [ | ||
OrderedImportsFixer::IMPORT_TYPE_CONST, | ||
OrderedImportsFixer::IMPORT_TYPE_FUNCTION, | ||
OrderedImportsFixer::IMPORT_TYPE_CLASS, | ||
], | ||
], | ||
'class_definition' => ['multiLineExtendsEachSingleLine' => true], | ||
'ternary_to_null_coalescing' => true, | ||
'yoda_style' => true, | ||
'compact_nullable_typehint' => true, | ||
'visibility_required' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder) | ||
; |
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,27 @@ | ||
sudo: required | ||
|
||
language: bash | ||
|
||
services: | ||
- docker | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- docker-ce | ||
|
||
install: | ||
- dev/bin/docker-compose build | ||
|
||
before_script: | ||
- dev/bin/php composer install --ansi --prefer-dist | ||
|
||
script: | ||
- dev/bin/php composer test -- --colors=always --coverage-clover=coverage.xml --debug | ||
- dev/bin/php composer lint -- --ansi --diff --dry-run --using-cache=no --verbose | ||
|
||
after_script: | ||
- dev/bin/docker-compose down --volumes | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
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,7 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] |
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,33 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Controller; | ||
|
||
use League\OAuth2\Server\AuthorizationServer; | ||
use League\OAuth2\Server\Exception\OAuthServerException; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Zend\Diactoros\Response; | ||
|
||
final class TokenController | ||
{ | ||
/** | ||
* @var AuthorizationServer | ||
*/ | ||
private $server; | ||
|
||
public function __construct(AuthorizationServer $server) | ||
{ | ||
$this->server = $server; | ||
} | ||
|
||
public function indexAction(ServerRequestInterface $serverRequest): ResponseInterface | ||
{ | ||
$serverResponse = new Response(); | ||
|
||
try { | ||
return $this->server->respondToAccessTokenRequest($serverRequest, $serverResponse); | ||
} catch (OAuthServerException $e) { | ||
return $e->generateHttpResponse($serverResponse); | ||
} | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Converter; | ||
|
||
use Trikoder\Bundle\OAuth2Bundle\League\Entity\Scope as ScopeEntity; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\Scope as ScopeModel; | ||
|
||
final class ScopeConverter | ||
{ | ||
public function toDomain(ScopeEntity $scope): ScopeModel | ||
{ | ||
return new ScopeModel($scope->getIdentifier()); | ||
} | ||
|
||
/** | ||
* @return ScopeModel[] | ||
*/ | ||
public function toDomainArray(array $scopes): array | ||
{ | ||
return array_map(function (ScopeEntity $scope): ScopeModel { | ||
return $this->toDomain($scope); | ||
}, $scopes); | ||
} | ||
|
||
public function toLeague(ScopeModel $scope): ScopeEntity | ||
{ | ||
$scopeEntity = new ScopeEntity(); | ||
$scopeEntity->setIdentifier((string) $scope); | ||
|
||
return $scopeEntity; | ||
} | ||
|
||
/** | ||
* @return ScopeEntity[] | ||
*/ | ||
public function toLeagueArray(array $scopes): array | ||
{ | ||
return array_map(function (ScopeModel $scope): ScopeEntity { | ||
return $this->toLeague($scope); | ||
}, $scopes); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\DBAL\Type; | ||
|
||
use Trikoder\Bundle\OAuth2Bundle\Model\Grant as GrantModel; | ||
|
||
final class Grant extends ImplodedArray | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const NAME = 'oauth2_grant'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function convertDatabaseValues(array $values): array | ||
{ | ||
foreach ($values as &$value) { | ||
$value = new GrantModel($value); | ||
} | ||
|
||
return $values; | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\DBAL\Type; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\TextType; | ||
use InvalidArgumentException; | ||
use LogicException; | ||
|
||
abstract class ImplodedArray extends TextType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const VALUE_DELIMITER = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
if (!\is_array($value)) { | ||
throw new LogicException('This type can only be used in combination with arrays.'); | ||
} | ||
|
||
if (0 === \count($value)) { | ||
return null; | ||
} | ||
|
||
foreach ($value as $item) { | ||
$this->assertValueCanBeImploded($item); | ||
} | ||
|
||
return implode(self::VALUE_DELIMITER, $value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
if (null === $value) { | ||
return []; | ||
} | ||
|
||
$values = explode(self::VALUE_DELIMITER, $value); | ||
|
||
return $this->convertDatabaseValues($values); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
{ | ||
$fieldDeclaration['length'] = 65535; | ||
|
||
return parent::getSQLDeclaration($fieldDeclaration, $platform); | ||
} | ||
|
||
private function assertValueCanBeImploded($value): void | ||
{ | ||
if (null === $value) { | ||
return; | ||
} | ||
|
||
if (is_scalar($value)) { | ||
return; | ||
} | ||
|
||
if (\is_object($value) && method_exists($value, '__toString')) { | ||
return; | ||
} | ||
|
||
throw new InvalidArgumentException( | ||
sprintf('The value of \'%s\' type cannot be imploded.', \gettype($value)) | ||
); | ||
} | ||
|
||
abstract protected function convertDatabaseValues(array $values): array; | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\DBAL\Type; | ||
|
||
use Trikoder\Bundle\OAuth2Bundle\Model\RedirectUri as RedirectUriModel; | ||
|
||
final class RedirectUri extends ImplodedArray | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const NAME = 'oauth2_redirect_uri'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function convertDatabaseValues(array $values): array | ||
{ | ||
foreach ($values as &$value) { | ||
$value = new RedirectUriModel($value); | ||
} | ||
|
||
return $values; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\DBAL\Type; | ||
|
||
use Trikoder\Bundle\OAuth2Bundle\Model\Scope as ScopeModel; | ||
|
||
final class Scope extends ImplodedArray | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const NAME = 'oauth2_scope'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function convertDatabaseValues(array $values): array | ||
{ | ||
foreach ($values as &$value) { | ||
$value = new ScopeModel($value); | ||
} | ||
|
||
return $values; | ||
} | ||
} |
Oops, something went wrong.