1- <?php namespace App \Http \Controllers \Api \OAuth2 ;
1+ <?php
2+ namespace App \Http \Controllers \Api \OAuth2 ;
23/**
34 * Copyright 2015 OpenStack Foundation
45 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,7 +60,7 @@ final class OAuth2UserApiController extends OAuth2ProtectedController
5960 tags: ['Users ' ],
6061 security: [
6162 [
62- 'user_oauth2 ' => [
63+ 'OAuth2UserSecurity ' => [
6364 IUserScopes::ReadAll,
6465 ]
6566 ],
@@ -105,7 +106,7 @@ final class OAuth2UserApiController extends OAuth2ProtectedController
105106 new OA \Response (
106107 response: HttpResponse::HTTP_OK ,
107108 description: 'OK ' ,
108- content: new OA \JsonContent (ref: '#/components/schemas/PaginatedUserResponseSchema ' )
109+ content: new OA \JsonContent (ref: '#/components/schemas/PaginatedUserResponse ' )
109110 ),
110111 new OA \Response (
111112 response: HttpResponse::HTTP_NOT_FOUND ,
@@ -197,8 +198,7 @@ public function __construct
197198 IOpenIdUserService $ openid_user_service ,
198199 IClientRepository $ client_repository ,
199200 IdTokenBuilder $ id_token_builder
200- )
201- {
201+ ) {
202202 parent ::__construct ($ resource_server_context , $ log_service );
203203 $ this ->repository = $ repository ;
204204 $ this ->user_service = $ user_service ;
@@ -217,13 +217,9 @@ public function __construct
217217 operationId: 'getCurrentUser ' ,
218218 tags: ['Users ' ],
219219 security: [
220- [
221- 'user_oauth2 ' => [
222- IUserScopes::Profile,
223- IUserScopes::Email,
224- IUserScopes::Address,
225- ]
226- ],
220+ ['OAuth2UserSecurity ' => [IUserScopes::Profile]],
221+ ['OAuth2UserSecurity ' => [IUserScopes::Email]],
222+ ['OAuth2UserSecurity ' => [IUserScopes::Address]],
227223 ],
228224 responses: [
229225 new OA \Response (
@@ -252,24 +248,27 @@ protected function curateUpdatePayload(array $payload): array
252248 {
253249 // remove possible fields that an user can not update
254250 // from this endpoint
255- if (isset ($ payload ['groups ' ]))
251+ if (isset ($ payload ['groups ' ]))
256252 unset($ payload ['groups ' ]);
257253
258- if (isset ($ payload ['email_verified ' ]))
254+ if (isset ($ payload ['email_verified ' ]))
259255 unset($ payload ['email_verified ' ]);
260256
261- if (isset ($ payload ['active ' ]))
257+ if (isset ($ payload ['active ' ]))
262258 unset($ payload ['active ' ]);
263259
264260 return HTMLCleaner::cleanData ($ payload , [
265- 'bio ' , 'statement_of_interest '
261+ 'bio ' ,
262+ 'statement_of_interest '
266263 ]);
267264 }
268265
269- private function _create (){
266+ private function _create ()
267+ {
270268 try {
271269
272- if (!Request::isJson ()) return $ this ->error400 ();
270+ if (!Request::isJson ())
271+ return $ this ->error400 ();
273272
274273 $ payload = Request::json ()->all ();
275274 // Creates a Validator instance and validates the data.
@@ -282,27 +281,24 @@ private function _create(){
282281 $ user = $ this ->openid_user_service ->create ($ payload );
283282
284283 return $ this ->created (SerializerRegistry::getInstance ()->getSerializer ($ user , SerializerRegistry::SerializerType_Private)->serialize ());
285- }
286- catch (ValidationException $ ex1 )
287- {
284+ } catch (ValidationException $ ex1 ) {
288285 Log::warning ($ ex1 );
289286 return $ this ->error412 ($ ex1 ->getMessages ());
290- }
291- catch (EntityNotFoundException $ ex2 )
292- {
287+ } catch (EntityNotFoundException $ ex2 ) {
293288 Log::warning ($ ex2 );
294289 return $ this ->error404 (['message ' => $ ex2 ->getMessage ()]);
295- }
296- catch (Exception $ ex ) {
290+ } catch (Exception $ ex ) {
297291 Log::error ($ ex );
298292 return $ this ->error500 ($ ex );
299293 }
300294 }
301295
302- private function _update ($ id ){
296+ private function _update ($ id )
297+ {
303298 try {
304299
305- if (!Request::isJson ()) return $ this ->error400 ();
300+ if (!Request::isJson ())
301+ return $ this ->error400 ();
306302
307303 $ payload = Request::json ()->all ();
308304 // Creates a Validator instance and validates the data.
@@ -315,18 +311,13 @@ private function _update($id){
315311 $ user = $ this ->openid_user_service ->update ($ id , $ this ->curateUpdatePayload ($ payload ));
316312
317313 return $ this ->updated (SerializerRegistry::getInstance ()->getSerializer ($ user , SerializerRegistry::SerializerType_Private)->serialize ());
318- }
319- catch (ValidationException $ ex1 )
320- {
314+ } catch (ValidationException $ ex1 ) {
321315 Log::warning ($ ex1 );
322316 return $ this ->error412 ($ ex1 ->getMessages ());
323- }
324- catch (EntityNotFoundException $ ex2 )
325- {
317+ } catch (EntityNotFoundException $ ex2 ) {
326318 Log::warning ($ ex2 );
327319 return $ this ->error404 (['message ' => $ ex2 ->getMessage ()]);
328- }
329- catch (Exception $ ex ) {
320+ } catch (Exception $ ex ) {
330321 Log::error ($ ex );
331322 return $ this ->error500 ($ ex );
332323 }
@@ -339,7 +330,7 @@ private function _update($id){
339330 tags: ['Users ' ],
340331 security: [
341332 [
342- 'user_oauth2 ' => [
333+ 'OAuth2UserSecurity ' => [
343334 IUserScopes::Write,
344335 ]
345336 ],
@@ -373,8 +364,9 @@ private function _update($id){
373364 ),
374365 ]
375366 )]
376- public function create (){
377- return $ this ->_create ();
367+ public function create ()
368+ {
369+ return $ this ->_create ();
378370 }
379371
380372 #[OA \Put(
@@ -384,7 +376,7 @@ public function create(){
384376 tags: ['Users ' ],
385377 security: [
386378 [
387- 'user_oauth2 ' => [
379+ 'OAuth2UserSecurity ' => [
388380 IUserScopes::MeWrite,
389381 ]
390382 ],
@@ -418,7 +410,8 @@ public function create(){
418410 ),
419411 ]
420412 )]
421- public function updateMe (){
413+ public function updateMe ()
414+ {
422415 return $ this ->_update ($ this ->resource_server_context ->getCurrentUserId ());
423416 }
424417
@@ -429,7 +422,7 @@ public function updateMe(){
429422 tags: ['Users ' ],
430423 security: [
431424 [
432- 'user_oauth2 ' => [
425+ 'OAuth2UserSecurity ' => [
433426 IUserScopes::Write,
434427 ]
435428 ],
@@ -472,8 +465,9 @@ public function updateMe(){
472465 ),
473466 ]
474467 )]
475- public function update ($ id ){
476- return $ this ->_update ($ id );
468+ public function update ($ id )
469+ {
470+ return $ this ->_update ($ id );
477471 }
478472
479473 #[OA \Put(
@@ -483,7 +477,7 @@ public function update($id){
483477 tags: ['Users ' ],
484478 security: [
485479 [
486- 'user_oauth2 ' => [
480+ 'OAuth2UserSecurity ' => [
487481 IUserScopes::MeWrite,
488482 ]
489483 ],
@@ -520,31 +514,27 @@ public function update($id){
520514 ),
521515 ]
522516 )]
523- public function updateMyPic (LaravelRequest $ request ){
517+ public function updateMyPic (LaravelRequest $ request )
518+ {
524519 try {
525520 if (!$ this ->resource_server_context ->getCurrentUserId ()) {
526521 return $ this ->error403 ();
527522 }
528523
529- $ file = $ request ->hasFile ('file ' ) ? $ request ->file ('file ' ): null ;
530- if (is_null ($ file )){
524+ $ file = $ request ->hasFile ('file ' ) ? $ request ->file ('file ' ) : null ;
525+ if (is_null ($ file )) {
531526 throw new ValidationException ('file is not present ' );
532527 }
533528 $ user = $ this ->openid_user_service ->updateProfilePhoto ($ this ->resource_server_context ->getCurrentUserId (), $ file );
534529
535530 return $ this ->updated (SerializerRegistry::getInstance ()->getSerializer ($ user , SerializerRegistry::SerializerType_Private)->serialize ());
536- }
537- catch (ValidationException $ ex1 )
538- {
531+ } catch (ValidationException $ ex1 ) {
539532 Log::warning ($ ex1 );
540533 return $ this ->error412 ($ ex1 ->getMessages ());
541- }
542- catch (EntityNotFoundException $ ex2 )
543- {
534+ } catch (EntityNotFoundException $ ex2 ) {
544535 Log::warning ($ ex2 );
545536 return $ this ->error404 (['message ' => $ ex2 ->getMessage ()]);
546- }
547- catch (Exception $ ex ) {
537+ } catch (Exception $ ex ) {
548538 Log::error ($ ex );
549539 return $ this ->error500 ($ ex );
550540 }
@@ -556,13 +546,9 @@ public function updateMyPic(LaravelRequest $request){
556546 operationId: 'getUserInfo ' ,
557547 tags: ['Users ' ],
558548 security: [
559- [
560- 'user_oauth2 ' => [
561- IUserScopes::Profile,
562- IUserScopes::Email,
563- IUserScopes::Address,
564- ]
565- ],
549+ ['OAuth2UserSecurity ' => [IUserScopes::Profile]],
550+ ['OAuth2UserSecurity ' => [IUserScopes::Email]],
551+ ['OAuth2UserSecurity ' => [IUserScopes::Address]],
566552 ],
567553 responses: [
568554 new OA \Response (
@@ -583,7 +569,7 @@ public function updateMyPic(LaravelRequest $request){
583569 tags: ['Users ' ],
584570 security: [
585571 [
586- 'user_oauth2 ' => [
572+ 'OAuth2UserSecurity ' => [
587573 IUserScopes::Profile,
588574 IUserScopes::Email,
589575 IUserScopes::Address,
@@ -645,7 +631,7 @@ public function userInfo()
645631 tags: ['Users ' ],
646632 security: [
647633 [
648- 'user_oauth2 ' => [
634+ 'OAuth2UserSecurity ' => [
649635 IUserScopes::ReadAll,
650636 ]
651637 ],
@@ -710,9 +696,11 @@ public function get($id)
710696 operationId: 'getUserByIdV2 ' ,
711697 tags: ['Users ' , 'V2 ' ],
712698 security: [
713- ['OAuth2UserSecurity ' => [
714- IUserScopes::ReadAll,
715- ]],
699+ [
700+ 'OAuth2UserSecurity ' => [
701+ IUserScopes::ReadAll,
702+ ]
703+ ],
716704 ],
717705 x: [
718706 'x-required-client-type ' => 'SERVICE ' ,
@@ -755,7 +743,7 @@ public function get($id)
755743 )]
756744 public function getV2 ($ id )
757745 {
758- return $ this ->processRequest (function () use ($ id ) {
746+ return $ this ->processRequest (function () use ($ id ) {
759747 $ user = $ this ->repository ->getById (intval ($ id ));
760748 if (is_null ($ user )) {
761749 throw new EntityNotFoundException ();
@@ -774,16 +762,19 @@ public function getV2($id)
774762 */
775763 #[OA \Put(
776764 path: '/api/v1/users/{id}/groups ' ,
777- summary: 'Update user group assignments (only for account type "SERVICE") ' ,
765+ summary: 'Update user group assignments ' ,
778766 operationId: 'updateUserGroups ' ,
779767 tags: ['Users ' ],
780768 security: [
781769 [
782- 'user_oauth2 ' => [
770+ 'OAuth2UserSecurity ' => [
783771 IUserScopes::UserGroupWrite,
784772 ]
785773 ],
786774 ],
775+ x: [
776+ 'x-required-client-type ' => 'SERVICE ' ,
777+ ],
787778 parameters: [
788779 new OA \Parameter (
789780 name: 'id ' ,
@@ -819,12 +810,17 @@ public function getV2($id)
819810 response: HttpResponse::HTTP_INTERNAL_SERVER_ERROR ,
820811 description: 'Server Error '
821812 ),
813+ new OA \Response (
814+ response: HttpResponse::HTTP_FORBIDDEN ,
815+ description: 'Forbidden - Only service accounts are allowed '
816+ ),
822817 ]
823818 )]
824819 public function updateUserGroups ($ user_id ): mixed
825820 {
826- return $ this ->processRequest (function () use ($ user_id ) {
827- if (!Request::isJson ()) return $ this ->error400 ();
821+ return $ this ->processRequest (function () use ($ user_id ) {
822+ if (!Request::isJson ())
823+ return $ this ->error400 ();
828824
829825 $ payload = Request::json ()->all ();
830826 // Creates a Validator instance and validates the data.
0 commit comments