1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* OAuth 2.0 Client credentials grant. |
4
|
|
|
* |
5
|
|
|
* @author Alex Bilbie <[email protected]> |
6
|
|
|
* @copyright Copyright (c) Alex Bilbie |
7
|
|
|
* @license http://mit-license.org/ |
8
|
|
|
* |
9
|
|
|
* @link https://github.com/thephpleague/oauth2-server |
10
|
|
|
*/ |
11
|
|
|
namespace League\OAuth2\Server\Grant; |
12
|
|
|
|
13
|
|
|
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; |
14
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Client credentials grant class. |
18
|
|
|
*/ |
19
|
|
|
class ClientCredentialsGrant extends AbstractGrant |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function respondToAccessTokenRequest( |
25
|
|
|
ServerRequestInterface $request, |
26
|
|
|
ResponseTypeInterface $responseType, |
27
|
|
|
\DateInterval $accessTokenTTL |
28
|
|
|
) { |
29
|
|
|
// Validate request |
30
|
|
|
$client = $this->validateClient($request); |
31
|
|
|
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request)); |
32
|
|
|
|
33
|
|
|
// Finalize the requested scopes |
34
|
|
|
$scopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client); |
35
|
|
|
|
36
|
|
|
// Issue and persist access token |
37
|
|
|
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, null, $scopes); |
38
|
|
|
|
39
|
|
|
// Inject access token into response type |
40
|
|
|
$responseType->setAccessToken($accessToken); |
41
|
|
|
|
42
|
|
|
return $responseType; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function getIdentifier() |
49
|
|
|
{ |
50
|
|
|
return 'client_credentials'; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|