mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
First commit of new examples
This commit is contained in:
51
examples/src/Repositories/ClientRepository.php
Normal file
51
examples/src/Repositories/ClientRepository.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace OAuth2ServerExamples\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\ClientEntity;
|
||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
|
||||
class ClientRepository implements ClientRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a client
|
||||
*
|
||||
* @param string $clientIdentifier The client's identifier
|
||||
* @param string $clientSecret The client's secret (default = "null")
|
||||
* @param string $redirectUri The client's redirect URI (default = "null")
|
||||
* @param string $grantType The grant type used (default = "null")
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
|
||||
*/
|
||||
public function get($clientIdentifier, $clientSecret = null, $redirectUri = null, $grantType = null)
|
||||
{
|
||||
$clients = [
|
||||
'myawesomeapp' => [
|
||||
'secret' => password_hash('abc123', PASSWORD_BCRYPT),
|
||||
'name' => 'My Awesome App',
|
||||
'redirect_uri' => ''
|
||||
]
|
||||
];
|
||||
|
||||
// Check if client is registered
|
||||
if (array_key_exists($clientIdentifier, $clients) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if client secret is valid
|
||||
if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if redirect URI is valid
|
||||
if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirectUri']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$client = new ClientEntity();
|
||||
$client->setIdentifier($clientIdentifier);
|
||||
$client->setName($clients[$clientIdentifier]['name']);
|
||||
$client->setSecret($clients[$clientIdentifier]['secret']);
|
||||
|
||||
return $client;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user