|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Authorization\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use FOS\OAuthServerBundle\Controller\TokenController; |
|
6
|
|
|
use FOS\OAuthServerBundle\Model\TokenInterface; |
|
7
|
|
|
use Nelmio\ApiDocBundle\Annotation\Operation; |
|
8
|
|
|
use Swagger\Annotations as SWG; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class OAuthTokenController |
|
15
|
|
|
* @package App\Authorization\Controller |
|
16
|
|
|
*/ |
|
17
|
|
|
class OAuthTokenController extends TokenController { |
|
18
|
|
|
/** |
|
19
|
|
|
* Get access token |
|
20
|
|
|
* @param Request $request |
|
21
|
|
|
* @return TokenInterface |
|
22
|
|
|
* |
|
23
|
|
|
* @Route("/oauth/v2/token") |
|
24
|
|
|
* @Method({"POST","GET"}) |
|
25
|
|
|
* |
|
26
|
|
|
* @Operation( |
|
27
|
|
|
* tags={"OAuth"}, |
|
28
|
|
|
* summary="Get access token", |
|
29
|
|
|
* @SWG\Parameter( |
|
30
|
|
|
* name="username", |
|
31
|
|
|
* in="formData", |
|
32
|
|
|
* description="User name (for `password` grant type)", |
|
33
|
|
|
* required=false, |
|
34
|
|
|
* type="string" |
|
35
|
|
|
* ), |
|
36
|
|
|
* @SWG\Parameter( |
|
37
|
|
|
* name="password", |
|
38
|
|
|
* in="formData", |
|
39
|
|
|
* description="User password (for `password` grant type)", |
|
40
|
|
|
* required=false, |
|
41
|
|
|
* type="string" |
|
42
|
|
|
* ), |
|
43
|
|
|
* |
|
44
|
|
|
* @SWG\Parameter( |
|
45
|
|
|
* name="client_id", |
|
46
|
|
|
* in="formData", |
|
47
|
|
|
* description="Client Id (for `client_credentials` grant type)", |
|
48
|
|
|
* required=false, |
|
49
|
|
|
* type="string" |
|
50
|
|
|
* ), |
|
51
|
|
|
* @SWG\Parameter( |
|
52
|
|
|
* name="client_secret", |
|
53
|
|
|
* in="formData", |
|
54
|
|
|
* description="Client Secret (for `client_credentials` grant type)", |
|
55
|
|
|
* required=false, |
|
56
|
|
|
* type="string" |
|
57
|
|
|
* ), |
|
58
|
|
|
* |
|
59
|
|
|
* @SWG\Parameter( |
|
60
|
|
|
* name="refresh_token", |
|
61
|
|
|
* in="formData", |
|
62
|
|
|
* description="The authorization code received by the authorization server(for `refresh_token` grant type`", |
|
63
|
|
|
* required=false, |
|
64
|
|
|
* type="string" |
|
65
|
|
|
* ), |
|
66
|
|
|
* @SWG\Parameter( |
|
67
|
|
|
* name="code", |
|
68
|
|
|
* in="formData", |
|
69
|
|
|
* description="The authorization code received by the authorization server (For `authorization_code` grant type)", |
|
70
|
|
|
* required=false, |
|
71
|
|
|
* type="string" |
|
72
|
|
|
* ), |
|
73
|
|
|
* @SWG\Parameter( |
|
74
|
|
|
* name="scope", |
|
75
|
|
|
* in="formData", |
|
76
|
|
|
* description="If the `redirect_uri` parameter was included in the authorization request, and their values MUST be identical", |
|
77
|
|
|
* required=false, |
|
78
|
|
|
* type="string" |
|
79
|
|
|
* ), |
|
80
|
|
|
* @SWG\Parameter( |
|
81
|
|
|
* name="redirect_uri", |
|
82
|
|
|
* in="formData", |
|
83
|
|
|
* description="If the `redirect_uri` parameter was included in the authorization request, and their values MUST be identical", |
|
84
|
|
|
* required=false, |
|
85
|
|
|
* type="string" |
|
86
|
|
|
* ), |
|
87
|
|
|
* |
|
88
|
|
|
* @SWG\Parameter( |
|
89
|
|
|
* name="grant_type", |
|
90
|
|
|
* in="formData", |
|
91
|
|
|
* description="refresh_token|authorization_code|password|client_credentials|custom", |
|
92
|
|
|
* required=false, |
|
93
|
|
|
* default="client_credentials", |
|
94
|
|
|
* type="string" |
|
95
|
|
|
* ), |
|
96
|
|
|
* @SWG\Response( |
|
97
|
|
|
* response="200", |
|
98
|
|
|
* description="Returned when successful" |
|
99
|
|
|
* ) |
|
100
|
|
|
* ) |
|
101
|
|
|
* |
|
102
|
|
|
*/ |
|
103
|
|
|
public function tokenAction(Request $request) |
|
104
|
|
|
{ |
|
105
|
|
|
if (!$request->request->get('grant_type')) { |
|
106
|
|
|
$request->request->set('grant_type', 'client_credentials'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return parent::tokenAction($request); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|