1212use PhpList \RestBundle \Common \Controller \BaseController ;
1313use PhpList \RestBundle \Common \Validator \RequestValidator ;
1414use PhpList \RestBundle \Identity \Request \CreateSessionRequest ;
15+ use PhpList \RestBundle \Identity \Serializer \AdministratorNormalizer ;
1516use PhpList \RestBundle \Identity \Serializer \AdministratorTokenNormalizer ;
1617use Symfony \Bridge \Doctrine \Attribute \MapEntity ;
1718use Symfony \Component \HttpFoundation \JsonResponse ;
@@ -36,6 +37,7 @@ public function __construct(
3637 RequestValidator $ validator ,
3738 SessionManager $ sessionManager ,
3839 private readonly EntityManagerInterface $ entityManager ,
40+ private readonly AdministratorNormalizer $ normalizer ,
3941 ) {
4042 parent ::__construct ($ authentication , $ validator );
4143
@@ -170,4 +172,46 @@ public function deleteSession(
170172
171173 return $ this ->json (null , Response::HTTP_NO_CONTENT );
172174 }
175+
176+ #[Route('/me ' , name: 'me ' , methods: ['GET ' ])]
177+ #[OA \Get(
178+ path: '/api/v2/sessions/me ' ,
179+ description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
180+ 'Get auth user data. ' ,
181+ summary: 'Get auth user data. ' ,
182+ tags: ['sessions ' ],
183+ parameters: [
184+ new OA \Parameter (
185+ name: 'php-auth-pw ' ,
186+ description: 'Session key obtained from login ' ,
187+ in: 'header ' ,
188+ required: true ,
189+ schema: new OA \Schema (type: 'string ' )
190+ ),
191+ ],
192+ responses: [
193+ new OA \Response (
194+ response: 200 ,
195+ description: 'Administrator found ' ,
196+ content: new OA \JsonContent (ref: '#/components/schemas/Administrator ' )
197+ ),
198+ new OA \Response (
199+ response: 401 ,
200+ description: 'Failure ' ,
201+ content: new OA \JsonContent (
202+ properties: [
203+ new OA \Property (property: 'message ' , type: 'string ' , example: 'Not authorized. ' )
204+ ]
205+ )
206+ )
207+ ]
208+ )]
209+ public function getSessionUser (Request $ request ): JsonResponse
210+ {
211+ $ administrator = $ this ->requireAuthentication ($ request );
212+
213+ $ json = $ this ->normalizer ->normalize ($ administrator , 'json ' );
214+
215+ return $ this ->json ($ json , Response::HTTP_OK );
216+ }
173217}
0 commit comments