2015-04-05 17:02:43 +01:00
|
|
|
<?php
|
2016-04-17 13:06:05 +01:00
|
|
|
/**
|
|
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
|
|
|
* @copyright Copyright (c) Alex Bilbie
|
|
|
|
* @license http://mit-license.org/
|
|
|
|
*
|
|
|
|
* @link https://github.com/thephpleague/oauth2-server
|
|
|
|
*/
|
2016-02-19 18:09:39 -05:00
|
|
|
|
2015-04-05 17:02:43 +01:00
|
|
|
namespace OAuth2ServerExamples\Repositories;
|
|
|
|
|
|
|
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
2016-03-15 21:54:36 +00:00
|
|
|
use OAuth2ServerExamples\Entities\ClientEntity;
|
2015-04-05 17:02:43 +01:00
|
|
|
|
|
|
|
class ClientRepository implements ClientRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2016-02-19 18:09:39 -05:00
|
|
|
* {@inheritdoc}
|
2015-04-05 17:02:43 +01:00
|
|
|
*/
|
2016-04-18 08:32:58 +01:00
|
|
|
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
|
2015-04-05 17:02:43 +01:00
|
|
|
{
|
|
|
|
$clients = [
|
|
|
|
'myawesomeapp' => [
|
2016-04-18 08:32:58 +01:00
|
|
|
'secret' => password_hash('abc123', PASSWORD_BCRYPT),
|
|
|
|
'name' => 'My Awesome App',
|
|
|
|
'redirect_uri' => 'http://foo/bar',
|
|
|
|
'is_confidential' => true,
|
2016-02-19 18:09:39 -05:00
|
|
|
],
|
2015-04-05 17:02:43 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
// Check if client is registered
|
|
|
|
if (array_key_exists($clientIdentifier, $clients) === false) {
|
2016-03-15 17:54:45 -04:00
|
|
|
return;
|
2015-04-05 17:02:43 +01:00
|
|
|
}
|
|
|
|
|
2016-04-18 08:32:58 +01:00
|
|
|
if (
|
|
|
|
$mustValidateSecret === true
|
|
|
|
&& $clients[$clientIdentifier]['is_confidential'] === true
|
|
|
|
&& password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-05 17:02:43 +01:00
|
|
|
$client = new ClientEntity();
|
|
|
|
$client->setIdentifier($clientIdentifier);
|
|
|
|
$client->setName($clients[$clientIdentifier]['name']);
|
2016-03-15 21:54:36 +00:00
|
|
|
$client->setRedirectUri($clients[$clientIdentifier]['redirect_uri']);
|
2015-04-05 17:02:43 +01:00
|
|
|
|
|
|
|
return $client;
|
|
|
|
}
|
|
|
|
}
|