1- <?php namespace App \Http \Controllers \Api \OAuth2 ;
1+ <?php
2+ namespace App \Http \Controllers \Api \OAuth2 ;
23/**
34 * Copyright 2020 OpenStack Foundation
45 * Licensed under the Apache License, Version 2.0 (the "License");
1718use models \exceptions \ValidationException ;
1819use OAuth2 \IResourceServerContext ;
1920use Utils \Services \ILogService ;
21+ use App \libs \OAuth2 \IUserScopes ;
22+ use OpenApi \Attributes as OA ;
23+ use Symfony \Component \HttpFoundation \Response as HttpResponse ;
2024/**
2125 * Class OAuth2RocketChatSSOApiController
2226 * @package App\Http\Controllers\Api\OAuth2
@@ -33,31 +37,68 @@ public function __construct
3337 IRocketChatSSOService $ service ,
3438 IResourceServerContext $ resource_server_context ,
3539 ILogService $ log_service
36- )
37- {
40+ ) {
3841 parent ::__construct ($ resource_server_context , $ log_service );
3942 $ this ->service = $ service ;
4043 }
4144
45+
46+ #[OA \Get(
47+ path: '/api/v1/sso/rocket-chat/{forum_slug}/profile ' ,
48+ operationId: 'getRocketChatUserProfile ' ,
49+ summary: 'Get Rocket Chat user profile for a forum. ' ,
50+ 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 ' ,
51+ security: [['OAuth2RocketChatSSOSecurity ' => [IUserScopes::SSO ]]],
52+ tags: ['Rocket Chat SSO ' ],
53+ parameters: [
54+ new OA \Parameter (
55+ name: 'forum_slug ' ,
56+ description: 'Forum slug ' ,
57+ in: 'path ' ,
58+ required: true ,
59+ schema: new OA \Schema (type: 'string ' )
60+ ),
61+ ],
62+ responses: [
63+ new OA \Response (
64+ response: HttpResponse::HTTP_OK ,
65+ description: 'OK, returns Rocket Chat user profile data on login success ' ,
66+ content: new OA \JsonContent (
67+ // The content of the response is defined by "data" portion of
68+ // the Rocket Chat login endpoint response structure
69+ ref: '#/components/schemas/RocketChatUserProfile ' ,
70+ )
71+ ),
72+ new OA \Response (
73+ response: HttpResponse::HTTP_NOT_FOUND ,
74+ description: 'Not Found '
75+ ),
76+ new OA \Response (
77+ response: HttpResponse::HTTP_PRECONDITION_FAILED ,
78+ description: 'Validation Error '
79+ ),
80+ new OA \Response (
81+ response: HttpResponse::HTTP_INTERNAL_SERVER_ERROR ,
82+ description: 'Server Error '
83+ ),
84+ ]
85+ )]
4286 /**
4387 * @param string $forum_slug
4488 * @return \Illuminate\Http\JsonResponse|mixed
4589 */
46- public function getUserProfile (string $ forum_slug ){
47- try {
90+ public function getUserProfile (string $ forum_slug )
91+ {
92+ try {
4893 $ profile = $ this ->service ->getUserProfile ($ forum_slug );
4994 return $ this ->ok ($ profile ->serialize ());
50- }
51- catch (ValidationException $ ex ) {
95+ } catch (ValidationException $ ex ) {
5296 Log::warning ($ ex );
5397 return $ this ->error412 ([$ ex ->getMessage ()]);
54- }
55- catch (EntityNotFoundException $ ex )
56- {
98+ } catch (EntityNotFoundException $ ex ) {
5799 Log::warning ($ ex );
58- return $ this ->error404 (['message ' => $ ex ->getMessage ()]);
59- }
60- catch (\Exception $ ex ) {
100+ return $ this ->error404 (['message ' => $ ex ->getMessage ()]);
101+ } catch (\Exception $ ex ) {
61102 Log::error ($ ex );
62103 return $ this ->error500 ($ ex );
63104 }
0 commit comments