Skip to content

Commit 86ebb1d

Browse files
Feat | Add OpenAPI documentation for OAuth2RocketChatSSOApiController v1 (#112)
* feat: Add OpenAPI documentation for OAuth2RocketChatSSOApiController v1 api routes * chore: Add PR requested changes * chore: Add PR requested changes
1 parent 802c8d8 commit 86ebb1d

3 files changed

Lines changed: 92 additions & 13 deletions

File tree

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

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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");
@@ -17,6 +18,9 @@
1718
use models\exceptions\ValidationException;
1819
use OAuth2\IResourceServerContext;
1920
use 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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'RocketChatUserProfile',
9+
type: 'object',
10+
additionalProperties: true,
11+
description: 'Rocket Chat SSO user profile. The response structure is the "data" portion of the Rocket Chat /api/v1/login endpoint response and is defined by the external Rocket Chat server.'
12+
)]
13+
class RocketChatUserProfileSchema
14+
{
15+
}
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: 'OAuth2RocketChatSSOSecurity',
10+
type: 'oauth2',
11+
description: 'OAuth2 authentication for Rocket 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 OAuth2RocketChatSSOApiControllerSecuritySchema
22+
{
23+
}

0 commit comments

Comments
 (0)