1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller; |
4
|
|
|
|
5
|
|
|
use Bone\Mvc\Controller; |
6
|
|
|
use DateTime; |
7
|
|
|
use Del\Common\ContainerService; |
8
|
|
|
use OAuth2\GrantType\ClientCredentials; |
9
|
|
|
use OAuth2\GrantType\AuthorizationCode; |
10
|
|
|
use OAuth2\GrantType\RefreshToken; |
11
|
|
|
use OAuth2\Server; |
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
use Zend\Diactoros\Response\SapiEmitter; |
14
|
|
|
|
15
|
|
|
class OAuthController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** @var Server $oauth2Server */ |
18
|
|
|
protected $oauth2Server; |
19
|
|
|
|
20
|
|
|
public function init() |
21
|
|
|
{ |
22
|
|
|
$container = ContainerService::getInstance()->getContainer(); |
23
|
|
|
$clientRepository = $container['repository.Client']; |
24
|
|
|
$accessTokenRepository = $container['repository.AccessToken']; |
25
|
|
|
$authCodeRepository = $container['repository.AuthCode']; |
26
|
|
|
$scopeRepository = $container['repository.Scope']; |
|
|
|
|
27
|
|
|
$userRepository = $container['repository.User']; |
28
|
|
|
$refreshTokenRepository = $container['repository.RefreshToken']; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
$server = new Server([ |
32
|
|
|
'client_credentials' => $clientRepository, |
33
|
|
|
'user_credentials' => $userRepository, |
34
|
|
|
'access_token' => $accessTokenRepository, |
35
|
|
|
'authorization_code' => $authCodeRepository, |
36
|
|
|
'refresh_token' => $refreshTokenRepository, |
37
|
|
|
], [ |
38
|
|
|
'auth_code_lifetime' => 30, |
39
|
|
|
'refresh_token_lifetime' => 30, |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
$server->addGrantType(new ClientCredentials($clientRepository)); |
43
|
|
|
$server->addGrantType(new AuthorizationCode($authCodeRepository)); |
44
|
|
|
$server->addGrantType(new RefreshToken($refreshTokenRepository, [ |
45
|
|
|
'always_issue_new_refresh_token' => true, |
46
|
|
|
])); |
47
|
|
|
|
48
|
|
|
$this->oauth2Server = $server; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Sends a response with the time |
54
|
|
|
*/ |
55
|
|
|
public function pingAction() |
56
|
|
|
{ |
57
|
|
|
$date = new DateTime(); |
58
|
|
|
$this->sendJsonResponse(['pong' => $date->format('Y-m-d H:i:s')]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param ResponseInterface $response |
63
|
|
|
*/ |
64
|
|
|
public function sendResponse(ResponseInterface $response) |
65
|
|
|
{ |
66
|
|
|
$emitter = new SapiEmitter(); |
67
|
|
|
$emitter->emit($response); |
68
|
|
|
exit(); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.