Skip to content

Commit

Permalink
Pass CryptKey instance to oauth2 with permission check disabled (#10)
Browse files Browse the repository at this point in the history
Disable permission checks for private/public keys
  • Loading branch information
gschafra authored and spideyfusion committed Dec 20, 2018
1 parent 9d0eac3 commit a24415a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
13 changes: 11 additions & 2 deletions DependencyInjection/TrikoderOAuth2Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Trikoder\Bundle\OAuth2Bundle\DependencyInjection;

use DateInterval;
use League\OAuth2\Server\CryptKey;
use LogicException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderInterface;
Expand Down Expand Up @@ -64,7 +65,11 @@ private function configureAuthorizationServer(ContainerBuilder $container, array
{
$authorizationServer = $container
->getDefinition('league.oauth2.server.authorization_server')
->replaceArgument('$privateKey', $config['private_key'])
->replaceArgument('$privateKey', new Definition(CryptKey::class, [
$config['private_key'],
null,
false,
]))
->replaceArgument('$encryptionKey', $config['encryption_key'])
;

Expand Down Expand Up @@ -160,7 +165,11 @@ private function configureResourceServer(ContainerBuilder $container, array $con
{
$container
->getDefinition('league.oauth2.server.resource_server')
->replaceArgument('$publicKey', $config['public_key'])
->replaceArgument('$publicKey', new Definition(CryptKey::class, [
$config['public_key'],
null,
false,
]))
;
}

Expand Down
5 changes: 3 additions & 2 deletions Tests/Integration/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Exception\CryptoException;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\Grant\PasswordGrant;
Expand Down Expand Up @@ -196,7 +197,7 @@ private function createAuthorizationServer(
$clientRepository,
$accessTokenRepository,
$scopeRepository,
TestHelper::PRIVATE_KEY_PATH,
new CryptKey(TestHelper::PRIVATE_KEY_PATH, null, false),
TestHelper::ENCRYPTION_KEY
);

Expand All @@ -211,7 +212,7 @@ private function createResourceServer(AccessTokenRepositoryInterface $accessToke
{
return new ResourceServer(
$accessTokenRepository,
TestHelper::PUBLIC_KEY_PATH
new CryptKey(TestHelper::PUBLIC_KEY_PATH, null, false)
);
}
}
2 changes: 1 addition & 1 deletion Tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function generateJwtToken(AccessTokenModel $accessToken): string
}

return $accessTokenEntity->convertToJWT(
new CryptKey(self::PRIVATE_KEY_PATH)
new CryptKey(self::PRIVATE_KEY_PATH, null, false)
);
}

Expand Down
4 changes: 0 additions & 4 deletions Tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public function boot()
putenv(sprintf('PUBLIC_KEY_PATH=%s', TestHelper::PUBLIC_KEY_PATH));
putenv(sprintf('ENCRYPTION_KEY=%s', TestHelper::ENCRYPTION_KEY));

// The authorization server requires proper file permissions for public/private keys.
chmod(TestHelper::PRIVATE_KEY_PATH, 0600);
chmod(TestHelper::PUBLIC_KEY_PATH, 0600);

parent::boot();
}

Expand Down

0 comments on commit a24415a

Please sign in to comment.