@@ 17-49 (lines=33) @@ | ||
14 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0 |
|
15 | * @see https://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-4.1 |
|
16 | */ |
|
17 | class CodeGrant extends Grant |
|
18 | { |
|
19 | /** @var string */ |
|
20 | private $code; |
|
21 | /** @var string */ |
|
22 | private $redirect_uri; |
|
23 | ||
24 | /** |
|
25 | * @param string $code |
|
26 | */ |
|
27 | public function __construct($code, $redirect_uri) |
|
28 | { |
|
29 | $this->code = $code; |
|
30 | $this->redirect_uri = $redirect_uri; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @param Client $http |
|
35 | * @param AuthFactory $factory |
|
36 | * @param Scope $scope |
|
37 | * @return \Psr\Http\Message\ResponseInterface |
|
38 | */ |
|
39 | public function auth(Client $http, AuthFactory $factory, Scope $scope) |
|
40 | { |
|
41 | return $http->request('POST', static::getPathToOAuthToken($factory->client), [ |
|
42 | 'form_params' => [ |
|
43 | 'grant_type' => 'authorization_code', |
|
44 | 'code' => $this->code, |
|
45 | 'scope' => (string)$scope, |
|
46 | ] + static::getFormParams($factory), |
|
47 | ]); |
|
48 | } |
|
49 | } |
|
50 |
@@ 16-50 (lines=35) @@ | ||
13 | * @copyright 2017 Baguette HQ |
|
14 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0 |
|
15 | */ |
|
16 | class PasswordCredential extends Grant |
|
17 | { |
|
18 | /** @var string */ |
|
19 | private $username; |
|
20 | /** @var string */ |
|
21 | private $password; |
|
22 | ||
23 | /** |
|
24 | * @param string $username |
|
25 | * @param string $password |
|
26 | */ |
|
27 | public function __construct($username, $password) |
|
28 | { |
|
29 | $this->username = $username; |
|
30 | $this->password = $password; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @param Client $http |
|
35 | * @param AuthFactory $factory |
|
36 | * @param Scope $scope |
|
37 | * @return \Psr\Http\Message\ResponseInterface |
|
38 | */ |
|
39 | public function auth(Client $http, AuthFactory $factory, Scope $scope) |
|
40 | { |
|
41 | return $http->request('POST', static::getPathToOAuthToken($factory->client), [ |
|
42 | 'form_params' => [ |
|
43 | 'grant_type' => 'password', |
|
44 | 'username' => $this->username, |
|
45 | 'password' => $this->password, |
|
46 | 'scope' => (string)$scope, |
|
47 | ] + static::getFormParamsWithSecret($factory), |
|
48 | ]); |
|
49 | } |
|
50 | } |
|
51 |