Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/oauth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
| Please see this link to find available grant types
| http://git.io/vJLAv
|
| This is an example that supports return type code and refresh tokens
| 'grant_types' => [
| 'authorization_code' => [
| 'class' => '\League\OAuth2\Server\Grant\AuthCodeGrant',
| 'access_token_ttl' => 36000,
| 'auth_token_ttl' => 36000
| ],
| 'refresh_token' => [
| 'class' => '\League\OAuth2\Server\Grant\RefreshTokenGrant',
| 'access_token_ttl' => 36000,
| 'refresh_token_ttl' => 360000000
| ]
|],
|
*/

'grant_types' => [
Expand Down
36 changes: 32 additions & 4 deletions src/Storage/FluentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ class FluentClient extends AbstractFluentAdapter implements ClientInterface
* @var bool
*/
protected $limitClientsToGrants = false;

/**
* Pre-register redirect url is required.
*
* @var bool
*/
protected $limitRedirectUri = false;
/**
* Create a new fluent client instance.
*
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
* @param bool $limitClientsToGrants
* @param bool $limitRedirectUri
*/
public function __construct(Resolver $resolver, $limitClientsToGrants = false)
public function __construct(Resolver $resolver, $limitClientsToGrants = false, $limitRedirectUri = false)
{
parent::__construct($resolver);
$this->limitClientsToGrants = $limitClientsToGrants;
$this->limitRedirectUri = $limitRedirectUri;
}

/**
Expand Down Expand Up @@ -77,7 +84,7 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
{
$query = null;

if (!is_null($redirectUri) && is_null($clientSecret)) {
if (!$this->limitRedirectUri === false && !is_null($redirectUri) && is_null($clientSecret)) {
$query = $this->getConnection()->table('oauth_clients')
->select(
'oauth_clients.id as id',
Expand All @@ -87,6 +94,13 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id')
->where('oauth_clients.id', $clientId)
->where('oauth_client_endpoints.redirect_uri', $redirectUri);
} elseif (!is_null($redirectUri) && is_null($clientSecret)) {
$query = $this->getConnection()->table('oauth_clients')
->select(
'oauth_clients.id as id',
'oauth_clients.secret as secret',
'oauth_clients.name as name')
->where('oauth_clients.id', $clientId);
} elseif (!is_null($clientSecret) && is_null($redirectUri)) {
$query = $this->getConnection()->table('oauth_clients')
->select(
Expand All @@ -95,7 +109,7 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
'oauth_clients.name as name')
->where('oauth_clients.id', $clientId)
->where('oauth_clients.secret', $clientSecret);
} elseif (!is_null($clientSecret) && !is_null($redirectUri)) {
} elseif ($this->limitRedirectUri === true && !is_null($clientSecret) && !is_null($redirectUri)) {
$query = $this->getConnection()->table('oauth_clients')
->select(
'oauth_clients.id as id',
Expand All @@ -106,6 +120,14 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
->where('oauth_clients.id', $clientId)
->where('oauth_clients.secret', $clientSecret)
->where('oauth_client_endpoints.redirect_uri', $redirectUri);
} elseif (!is_null($clientSecret) && !is_null($redirectUri)) {
$query = $this->getConnection()->table('oauth_clients')
->select(
'oauth_clients.id as id',
'oauth_clients.secret as secret',
'oauth_clients.name as name')
->where('oauth_clients.id', $clientId)
->where('oauth_clients.secret', $clientSecret);
}

if ($this->limitClientsToGrants === true && !is_null($grantType)) {
Expand All @@ -120,6 +142,12 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
return;
}

//populate redirect_uri in case where it is not in DB
if (!$this->limitRedirectUri){
$result->redirect_uri = 'not required';
}


return $this->hydrateEntity($result);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Storage/FluentStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function registerStorageBindings(Application $app)

$app->singleton(FluentClient::class, function ($app) use ($provider) {
$limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants');
$storage = new FluentClient($provider->app['db'], $limitClientsToGrants);
$limitRedirectUri = $app['config']->get('oauth2.limit_clients_to_predefined_url');
$storage = new FluentClient($provider->app['db'], $limitClientsToGrants, $limitRedirectUri);
$storage->setConnectionName($provider->getConnectionName());

return $storage;
Expand Down