UserRepository.php in Simple OAuth (OAuth2) & OpenID Connect 8.4
File
src/Repositories/UserRepository.php
View source
<?php
namespace Drupal\simple_oauth\Repositories;
use Drupal\user\UserAuthInterface;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use Drupal\simple_oauth\Entities\UserEntity;
class UserRepository implements UserRepositoryInterface {
protected $userAuth;
public function __construct(UserAuthInterface $user_auth) {
$this->userAuth = $user_auth;
}
public function getUserEntityByUserCredentials($username, $password, $grantType, ClientEntityInterface $clientEntity) {
if ($uid = $this->userAuth
->authenticate($username, $password)) {
$user = new UserEntity();
$user
->setIdentifier($uid);
return $user;
}
throw OAuthServerException::invalidCredentials();
}
}