1 | <?php |
||
14 | class TokenController extends BaseController |
||
15 | { |
||
16 | const TOKEN_TYPE = 'Bearer'; |
||
17 | |||
18 | /** |
||
19 | * @api {post} /token Получение токена |
||
20 | * @apiName CreateToken |
||
21 | * @apiGroup Token |
||
22 | * |
||
23 | * @apiDescription Метод для получения авторизационного токена. Токен необходим для выполнения запросов к АПИ. |
||
24 | * Полученный токен отправляется в заголовке запроса: |
||
25 | * <br/> |
||
26 | * <strong>Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</strong> |
||
27 | * |
||
28 | * @apiParam {String} username Логин |
||
29 | * @apiParam {String} password Пароль |
||
30 | * |
||
31 | * @apiParamExample {json} Пример запроса: |
||
32 | * { |
||
33 | * "data":{ |
||
34 | * "attributes":{ |
||
35 | * "username":"[email protected]", |
||
36 | * "password": "qwerty" |
||
37 | * } |
||
38 | * } |
||
39 | * } |
||
40 | * |
||
41 | * @apiSuccessExample {json} Успешно (200) |
||
42 | * HTTP/1.1 200 OK |
||
43 | * { |
||
44 | * "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOmZhbHNlLCJhdWQiOiJza2VsZXRvbi5kZXYiLCJpYXQiOjE0NzY0Mjk4NjksImV4cCI6MTQ3NjQzMzQ2OX0.NJn_-lK28kEZyZqygLr6B-FZ2zC2-1unStayTGicP5g", |
||
45 | * "expires_in": 3600, |
||
46 | * "token_type": "Bearer", |
||
47 | * "refresh_token": "092ea7e36f6b9bf462cb3ca1f6f86b80" |
||
48 | * } |
||
49 | * |
||
50 | * @apiUse StandardErrors |
||
51 | */ |
||
52 | /** |
||
53 | * @param Request $request |
||
54 | * @param Response $response |
||
55 | * |
||
56 | * @return \Psr\Http\Message\ResponseInterface |
||
57 | * @throws JsonException |
||
58 | */ |
||
59 | public function getToken(Request $request, Response $response) |
||
72 | |||
73 | /** |
||
74 | * @api {post} /refresh-token Обновление токена |
||
75 | * @apiName RefreshToken |
||
76 | * @apiGroup Token |
||
77 | * |
||
78 | * @apiDescription Метод для обновления access_token по refresh_token |
||
79 | * |
||
80 | * @apiParam {String} refresh_token Токен для обновления |
||
81 | * |
||
82 | * @apiParamExample {json} Пример запроса: |
||
83 | * { |
||
84 | * "data":{ |
||
85 | * "attributes":{ |
||
86 | * "refresh_token":"092ea7e36f6b9bf462cb3ca1f6f86b80" |
||
87 | * } |
||
88 | * } |
||
89 | * } |
||
90 | * |
||
91 | * @apiSuccessExample {json} Успешно (200) |
||
92 | * HTTP/1.1 200 OK |
||
93 | * { |
||
94 | * "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOmZhbHNlLCJhdWQiOiJza2VsZXRvbi5kZXYiLCJpYXQiOjE0NzY0Mjk4NjksImV4cCI6MTQ3NjQzMzQ2OX0.NJn_-lK28kEZyZqygLr6B-FZ2zC2-1unStayTGicP5g", |
||
95 | * "expires_in": 3600, |
||
96 | * "token_type": "Bearer", |
||
97 | * "refresh_token": "092ea7e36f6b9bf462cb3ca1f6f86b80" |
||
98 | * } |
||
99 | * |
||
100 | * @apiUse StandardErrors |
||
101 | */ |
||
102 | |||
103 | /** |
||
104 | * @param Request $request |
||
105 | * @param Response $response |
||
106 | * |
||
107 | * @return \Psr\Http\Message\ResponseInterface |
||
108 | * @throws JsonException |
||
109 | */ |
||
110 | public function refreshToken(Request $request, Response $response) |
||
123 | |||
124 | /** |
||
125 | * @param Request $request |
||
126 | * @param Response $response |
||
127 | * @param User $user |
||
128 | * @return \Psr\Http\Message\ResponseInterface |
||
129 | */ |
||
130 | protected function buildTokens(Request $request, Response $response, User $user) |
||
148 | } |
||
149 |