1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Mvdstam\Oauth2ServerLaravel\Http\Controllers; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Illuminate\Routing\Controller; |
8
|
|
|
use League\OAuth2\Server\AuthorizationServer; |
9
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
10
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
11
|
|
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface; |
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
use RuntimeException; |
15
|
|
|
|
16
|
|
|
class OAuth2Controller extends Controller |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var AuthorizationServer |
21
|
|
|
*/ |
22
|
|
|
protected $authorizationServer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var AccessTokenRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
protected $accessTokens; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* OAuth2Controller constructor. |
31
|
|
|
* @param AuthorizationServer $authorizationServer |
32
|
|
|
* @param AccessTokenRepositoryInterface $accessTokens |
33
|
|
|
*/ |
34
|
16 |
|
public function __construct(AuthorizationServer $authorizationServer, AccessTokenRepositoryInterface $accessTokens) |
35
|
|
|
{ |
36
|
16 |
|
$this->authorizationServer = $authorizationServer; |
37
|
16 |
|
$this->accessTokens = $accessTokens; |
38
|
16 |
|
} |
39
|
|
|
|
40
|
13 |
|
public function accessToken(ServerRequestInterface $request, ResponseInterface $response) |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
13 |
|
return $this->authorizationServer->respondToAccessTokenRequest( |
44
|
13 |
|
$request, |
45
|
13 |
|
$response |
46
|
|
|
); |
47
|
3 |
|
} catch (OAuthServerException $e) { |
48
|
3 |
|
return $e->generateHttpResponse($response); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
public function revokeAccessToken(ServerRequestInterface $request, ResponseInterface $response) |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
3 |
|
$this->accessTokens->revokeAccessToken($request->getAttribute('oauth_access_token_id')); |
56
|
1 |
|
} catch (OAuthServerException $e) { |
57
|
1 |
|
return $e->generateHttpResponse($response); |
58
|
|
|
} |
59
|
2 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Validates the authorization request and stores it in the session during authentication |
63
|
|
|
* of the user. |
64
|
|
|
* |
65
|
|
|
* @param ServerRequestInterface $request |
66
|
|
|
* @param ResponseInterface $response |
67
|
|
|
* @return ResponseInterface |
68
|
|
|
*/ |
69
|
|
|
public function authorize(ServerRequestInterface $request, ResponseInterface $response) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
throw new RuntimeException('Not implemented'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Finalizes the authorization process and returns an access code. |
76
|
|
|
* |
77
|
|
|
* @param UserRepositoryInterface $users |
78
|
|
|
* @param ServerRequestInterface $response |
79
|
|
|
* @return ResponseInterface |
80
|
|
|
*/ |
81
|
|
|
public function completeAuthorization(UserRepositoryInterface $users, ServerRequestInterface $request, ResponseInterface $response) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
throw new RuntimeException('Not implemented'); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.