oauth2-server/examples/src/Repositories/ClientRepository.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2015-04-05 17:02:43 +01:00
<?php
2016-02-19 18:09:39 -05:00
2015-04-05 17:02:43 +01:00
namespace OAuth2ServerExamples\Repositories;
use League\OAuth2\Server\Entities\ClientEntity;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class ClientRepository implements ClientRepositoryInterface
{
/**
2016-02-19 18:09:39 -05:00
* {@inheritdoc}
2015-04-05 17:02:43 +01:00
*/
public function getClientEntity($clientIdentifier, $clientSecret = null, $redirectUri = null, $grantType = null)
2015-04-05 17:02:43 +01:00
{
$clients = [
'myawesomeapp' => [
'secret' => password_hash('abc123', PASSWORD_BCRYPT),
'name' => 'My Awesome App',
2016-02-19 18:09:39 -05:00
'redirect_uri' => 'http://foo/bar',
],
2015-04-05 17:02:43 +01:00
];
// Check if client is registered
if (array_key_exists($clientIdentifier, $clients) === false) {
2016-02-19 18:09:39 -05:00
return;
2015-04-05 17:02:43 +01:00
}
// Check if client secret is valid
if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) {
2016-02-19 18:09:39 -05:00
return;
2015-04-05 17:02:43 +01:00
}
// Check if redirect URI is valid
2016-02-12 14:17:58 +00:00
if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirect_uri']) {
2016-02-19 18:09:39 -05:00
return;
2015-04-05 17:02:43 +01:00
}
$client = new ClientEntity();
$client->setIdentifier($clientIdentifier);
$client->setName($clients[$clientIdentifier]['name']);
return $client;
}
}