diff --git a/app/Http/Controllers/Api/OAuth2/OAuth2RocketChatSSOApiController.php b/app/Http/Controllers/Api/OAuth2/OAuth2RocketChatSSOApiController.php index 8e7d82cb..0e6d070d 100644 --- a/app/Http/Controllers/Api/OAuth2/OAuth2RocketChatSSOApiController.php +++ b/app/Http/Controllers/Api/OAuth2/OAuth2RocketChatSSOApiController.php @@ -1,4 +1,5 @@ -service = $service; } + + #[OA\Get( + path: '/api/v1/sso/rocket-chat/{forum_slug}/profile', + operationId: 'getRocketChatUserProfile', + summary: 'Get Rocket Chat user profile for a forum.', + description: 'Returns Rocket Chat user profile data for the authenticated user in the context of the specified forum. The content of the response is defined by "data" portion of the Rocket Chat login endpoint response structure', + security: [['OAuth2RocketChatSSOSecurity' => [IUserScopes::SSO]]], + tags: ['Rocket Chat SSO'], + parameters: [ + new OA\Parameter( + name: 'forum_slug', + description: 'Forum slug', + in: 'path', + required: true, + schema: new OA\Schema(type: 'string') + ), + ], + responses: [ + new OA\Response( + response: HttpResponse::HTTP_OK, + description: 'OK, returns Rocket Chat user profile data on login success', + content: new OA\JsonContent( + // The content of the response is defined by "data" portion of + // the Rocket Chat login endpoint response structure + red: '#/components/schemas/RocketChatUserProfile', + ) + ), + new OA\Response( + response: HttpResponse::HTTP_NOT_FOUND, + description: 'Not Found' + ), + new OA\Response( + response: HttpResponse::HTTP_PRECONDITION_FAILED, + description: 'Validation Error' + ), + new OA\Response( + response: HttpResponse::HTTP_INTERNAL_SERVER_ERROR, + description: 'Server Error' + ), + ] + )] /** * @param string $forum_slug * @return \Illuminate\Http\JsonResponse|mixed */ - public function getUserProfile(string $forum_slug){ - try{ + public function getUserProfile(string $forum_slug) + { + try { $profile = $this->service->getUserProfile($forum_slug); return $this->ok($profile->serialize()); - } - catch (ValidationException $ex) { + } catch (ValidationException $ex) { Log::warning($ex); return $this->error412([$ex->getMessage()]); - } - catch(EntityNotFoundException $ex) - { + } catch (EntityNotFoundException $ex) { Log::warning($ex); - return $this->error404(['message'=> $ex->getMessage()]); - } - catch (\Exception $ex) { + return $this->error404(['message' => $ex->getMessage()]); + } catch (\Exception $ex) { Log::error($ex); return $this->error500($ex); } diff --git a/app/Swagger/Models/RocketChatUserProfileSchema.php b/app/Swagger/Models/RocketChatUserProfileSchema.php new file mode 100644 index 00000000..c5af2f59 --- /dev/null +++ b/app/Swagger/Models/RocketChatUserProfileSchema.php @@ -0,0 +1,16 @@ + 'Single Sign-On access'] + ), + ] +)] +class OAuth2RocketChatSSOApiControllerSecuritySchema +{ +} \ No newline at end of file