Skip to content

Commit 77482f2

Browse files
feat: Add OpenAPI documentation annotations for OAuth2StreamChatSSOApiController v1 routes
1 parent 6d23f7f commit 77482f2

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

app/Http/Controllers/Api/OAuth2/OAuth2StreamChatSSOApiController.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
**/
14+
use App\libs\OAuth2\IUserScopes;
1415
use App\Services\Auth\IStreamChatSSOService;
1516
use Illuminate\Support\Facades\Log;
1617
use models\exceptions\EntityNotFoundException;
1718
use models\exceptions\ValidationException;
1819
use OAuth2\IResourceServerContext;
20+
use OpenApi\Attributes as OA;
21+
use Symfony\Component\HttpFoundation\Response as HttpResponse;
1922
use Utils\Services\ILogService;
2023
/**
2124
* Class OAuth2StreamChatSSOApiController
@@ -44,6 +47,50 @@ public function __construct
4447
* @param string $forum_slug
4548
* @return \Illuminate\Http\JsonResponse|mixed
4649
*/
50+
#[OA\Get(
51+
path: '/api/v1/sso/stream-chat/{forum_slug}/profile',
52+
operationId: 'getStreamChatUserProfile',
53+
summary: 'Get Stream Chat user profile for a forum',
54+
description: 'Returns the Stream Chat user profile and authentication token for the given forum. Requires SSO scope.',
55+
security: [['OAuth2StreamChatSSOSecurity' => [IUserScopes::SSO]]],
56+
tags: ['Stream Chat SSO'],
57+
parameters: [
58+
new OA\Parameter(
59+
name: 'forum_slug',
60+
description: 'Forum slug',
61+
in: 'path',
62+
required: true,
63+
schema: new OA\Schema(type: 'string')
64+
),
65+
],
66+
responses: [
67+
new OA\Response(
68+
response: HttpResponse::HTTP_OK,
69+
description: 'OK',
70+
content: new OA\JsonContent(ref: '#/components/schemas/StreamChatUserProfile')
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+
new OA\Response(
85+
response: HttpResponse::HTTP_UNAUTHORIZED,
86+
description: 'Unauthorized - invalid or missing token'
87+
),
88+
new OA\Response(
89+
response: HttpResponse::HTTP_FORBIDDEN,
90+
description: 'Forbidden - insufficient scope'
91+
),
92+
]
93+
)]
4794
public function getUserProfile(string $forum_slug){
4895
try{
4996
$profile = $this->service->getUserProfile($forum_slug);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'StreamChatUserProfile',
9+
type: 'object',
10+
properties: [
11+
new OA\Property(property: 'id', type: 'string', description: 'User ID'),
12+
new OA\Property(property: 'name', type: 'string', description: 'Display name'),
13+
new OA\Property(property: 'image', type: 'string', format: 'uri', description: 'Avatar URL'),
14+
new OA\Property(property: 'token', type: 'string', description: 'Stream Chat JWT token'),
15+
new OA\Property(property: 'api_key', type: 'string', description: 'Stream Chat API key'),
16+
new OA\Property(property: 'local_role', type: 'string', description: 'User role in the forum'),
17+
],
18+
description: 'Stream Chat SSO user profile'
19+
)]
20+
class StreamChatUserProfileSchema
21+
{
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use App\libs\OAuth2\IUserScopes;
6+
use OpenApi\Attributes as OA;
7+
8+
#[OA\SecurityScheme(
9+
securityScheme: 'OAuth2StreamChatSSOSecurity',
10+
type: 'oauth2',
11+
description: 'OAuth2 authentication for Stream Chat SSO endpoints',
12+
flows: [
13+
new OA\Flow(
14+
flow: 'authorizationCode',
15+
authorizationUrl: L5_SWAGGER_CONST_AUTH_URL,
16+
tokenUrl: L5_SWAGGER_CONST_TOKEN_URL,
17+
scopes: [IUserScopes::SSO => 'Single Sign-On access']
18+
),
19+
]
20+
)]
21+
class OAuth2StreamChatSSOApiControllerSecuritySchema
22+
{
23+
}

0 commit comments

Comments
 (0)