| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Module\OAuth\Repositories;
- use App\Module\OAuth\Models\OAuthClient;
- use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
- use League\OAuth2\Server\Entities\ClientEntityInterface;
- use League\OAuth2\Server\Entities\Traits\ClientTrait;
- use League\OAuth2\Server\Entities\Traits\EntityTrait;
- class ClientRepository implements ClientRepositoryInterface
- {
- public function getClientEntity($clientIdentifier)
- {
- $client = OAuthClient::where('client_id', $clientIdentifier)->first();
- if (!$client) {
- return null;
- }
- return new class($client) implements ClientEntityInterface {
- use EntityTrait, ClientTrait;
- private $client;
- public function __construct($client)
- {
- $this->client = $client;
- $this->setIdentifier($client->client_id);
- $this->name = $client->name;
- $this->redirectUri = $client->redirect_uri;
- }
- public function isConfidential()
- {
- return true;
- }
- };
- }
- public function validateClient($clientIdentifier, $clientSecret, $grantType)
- {
- $client = OAuthClient::where('client_id', $clientIdentifier)
- ->where('client_secret', $clientSecret)
- ->first();
- if (!$client) {
- return false;
- }
- return in_array($grantType, $client->grant_types);
- }
- }
|