Cheetah
UserCredentials.php
Go to the documentation of this file.
1 <?php
2 
3 namespace OAuth2\GrantType;
4 
9 
15 {
16  private $userInfo;
17 
18  protected $storage;
19 
24  {
25  $this->storage = $storage;
26  }
27 
28  public function getQuerystringIdentifier()
29  {
30  return 'password';
31  }
32 
33  public function validateRequest(RequestInterface $request, ResponseInterface $response)
34  {
35  if (!$request->request("password") || !$request->request("username")) {
36  $response->setError(400, 'invalid_request', 'Missing parameters: "username" and "password" required');
37 
38  return null;
39  }
40 
41  if (!$this->storage->checkUserCredentials($request->request("username"), $request->request("password"))) {
42  $response->setError(401, 'invalid_grant', 'Invalid username and password combination');
43 
44  return null;
45  }
46 
47  $userInfo = $this->storage->getUserDetails($request->request("username"));
48 
49  if (empty($userInfo)) {
50  $response->setError(400, 'invalid_grant', 'Unable to retrieve user information');
51 
52  return null;
53  }
54 
55  if (!isset($userInfo['user_id'])) {
56  throw new \LogicException("you must set the user_id on the array returned by getUserDetails");
57  }
58 
59  $this->userInfo = $userInfo;
60 
61  return true;
62  }
63 
64  public function getClientId()
65  {
66  return null;
67  }
68 
69  public function getUserId()
70  {
71  return $this->userInfo['user_id'];
72  }
73 
74  public function getScope()
75  {
76  return isset($this->userInfo['scope']) ? $this->userInfo['scope'] : null;
77  }
78 
79  public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
80  {
81  return $accessToken->createAccessToken($client_id, $user_id, $scope);
82  }
83 }
OAuth2\GrantType\GrantTypeInterface
Definition: GrantTypeInterface.php:13
OAuth2\GrantType\UserCredentials\getQuerystringIdentifier
getQuerystringIdentifier()
Definition: UserCredentials.php:28
OAuth2\RequestInterface\request
request($name, $default=null)
OAuth2\GrantType\UserCredentials\$storage
$storage
Definition: UserCredentials.php:18
OAuth2\GrantType\UserCredentials\__construct
__construct(UserCredentialsInterface $storage)
Definition: UserCredentials.php:23
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
OAuth2\GrantType
Definition: AuthorizationCode.php:3
php
OAuth2\GrantType\UserCredentials\validateRequest
validateRequest(RequestInterface $request, ResponseInterface $response)
Definition: UserCredentials.php:33
OAuth2\Storage\UserCredentialsInterface
Definition: UserCredentialsInterface.php:13
OAuth2\ResponseType\AccessTokenInterface
Definition: AccessTokenInterface.php:10
OAuth2\GrantType\UserCredentials\getClientId
getClientId()
Definition: UserCredentials.php:64
OAuth2\GrantType\UserCredentials
Definition: UserCredentials.php:15
OAuth2\ResponseInterface\setError
setError($statusCode, $name, $description=null, $uri=null)
OAuth2\ResponseInterface
Definition: ResponseInterface.php:12
OAuth2\ResponseType\AccessTokenInterface\createAccessToken
createAccessToken($client_id, $user_id, $scope=null, $includeRefreshToken=true)
OAuth2\RequestInterface
Definition: RequestInterface.php:6
OAuth2\GrantType\UserCredentials\getUserId
getUserId()
Definition: UserCredentials.php:69
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
OAuth2\GrantType\UserCredentials\getScope
getScope()
Definition: UserCredentials.php:74
OAuth2\GrantType\UserCredentials\createAccessToken
createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
Definition: UserCredentials.php:79