1 | <?php |
||
23 | class ClientCredentialsGrant extends AbstractGrant |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 5 | public function respondToAccessTokenRequest( |
|
29 | ServerRequestInterface $request, |
||
30 | ResponseTypeInterface $responseType, |
||
31 | DateInterval $accessTokenTTL |
||
32 | ) { |
||
33 | 5 | list($clientId) = $this->getClientCredentials($request); |
|
34 | |||
35 | 5 | $client = $this->getClientEntityOrFail($clientId, $request); |
|
36 | |||
37 | 4 | if (!$client->isConfidential()) { |
|
38 | 1 | $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); |
|
39 | |||
40 | 1 | throw OAuthServerException::invalidClient($request); |
|
41 | } |
||
42 | |||
43 | // Validate request |
||
44 | 3 | $this->validateClient($request); |
|
45 | |||
46 | 3 | $scopes = $this->validateScopes($this->getRequestParameter('scope', $request, $this->defaultScope)); |
|
47 | |||
48 | // Finalize the requested scopes |
||
49 | 3 | $finalizedScopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client); |
|
50 | |||
51 | // Issue and persist access token |
||
52 | 3 | $accessToken = $this->issueAccessToken($accessTokenTTL, $client, null, $finalizedScopes); |
|
53 | |||
54 | // Send event to emitter |
||
55 | 3 | $this->getEmitter()->emit(new RequestEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request)); |
|
56 | |||
57 | // Inject access token into response type |
||
58 | 3 | $responseType->setAccessToken($accessToken); |
|
|
|||
59 | |||
60 | 3 | return $responseType; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 7 | public function getIdentifier() |
|
70 | } |
||
71 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: