Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,20 @@ public function updateLeadReportSettings($summit_id) {
);
});
}

/**
* @param $summit_id
* @return mixed
*/
public function getQREncKey($summit_id) {
return $this->processRequest(function () use ($summit_id) {
$summit = SummitFinderStrategyFactory::build($this->getSummitRepository(), $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();

return $this->ok(SerializerRegistry::getInstance()
->getSerializer($summit, SummitQREncKeySerializer::SerializerType)
->serialize()
);
});
}
}
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ class Kernel extends HttpKernel
'cache' => \App\Http\Middleware\CacheMiddleware::class,
'ssl' => \App\Http\Middleware\SSLMiddleware::class,
'auth.user' => \App\Http\Middleware\UserAuthEndpoint::class,
'service.account' => \App\Http\Middleware\EnsureServiceAccount::class,
];
}
49 changes: 49 additions & 0 deletions app/Http/Middleware/EnsureServiceAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php namespace App\Http\Middleware;

/**
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use Closure;
use models\oauth2\IResourceServerContext;
use Illuminate\Support\Facades\Response;

final class EnsureServiceAccount
{
/**
* @var IResourceServerContext
*/
private $context;

/**
* EnsureServiceAccount constructor.
* @param IResourceServerContext $context
*/
public function __construct(IResourceServerContext $context)
{
$this->context = $context;
}

/**
* @param $request
* @param Closure $next
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function handle($request, Closure $next)
{
$application_type = $this->context->getApplicationType();
if ($application_type != IResourceServerContext::ApplicationType_Service) {
return Response::json(['error' => 'Only service accounts are allowed.'], 403);
}
return $next($request);
}
}
2 changes: 2 additions & 0 deletions app/Security/SummitScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ final class SummitScopes

const WriteAttendeeNotesData = '%s/attendee/notes/write';
const ReadAttendeeNotesData = '%s/attendee/notes/read';

const ReadSummitsEncKey = '%s/summits/read-enc-key';
}
8 changes: 8 additions & 0 deletions database/seeders/ApiEndpointsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8819,6 +8819,14 @@ private function seedSummitEndpoints()
IGroup::Administrators
]
],
[
'name' => 'retrieve-qr-enc-key',
'route' => '/api/v1/summits/{id}/qr-codes-enc-key',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadSummitsEncKey, $current_realm)
]
],
[
'name' => 'get-registration-feed-metadata',
'route' => '/api/v1/summits/{id}/registration-feed-metadata',
Expand Down
7 changes: 6 additions & 1 deletion database/seeders/ApiScopesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ private function seedSummitScopes()
'name' => sprintf(SummitScopes::WriteAttendeeNotesData, $current_realm),
'short_description' => 'Write Attendee Notes Data',
'description' => 'Grants write access for Attendee Notes Data',
]
],
[
'name' => sprintf(SummitScopes::ReadSummitsEncKey, $current_realm),
'short_description' => 'Read Summit QR Codes Enc Key',
'description' => 'Grants read only access for Summit QR Codes Encryption Key',
],
];

foreach ($scopes as $scope_info) {
Expand Down
4 changes: 4 additions & 0 deletions routes/api_v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@
});
});

//qr-code-enc-keys

Route::get('qr-codes-enc-key', ['middleware' => 'service.account', 'uses' => 'OAuth2SummitApiController@getQREncKey']);

// registration-feed-metadata

Route::group(['prefix' => 'registration-feed-metadata'], function(){
Expand Down
24 changes: 24 additions & 0 deletions tests/OAuth2SummitApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1149,4 +1149,28 @@ public function testUpdateSummitRegSlugPrefixHavingPaidTickets(){
$this->assertResponseStatus(412);
$this->assertStringContainsString('there are paid tickets', $content);
}

public function testGetQREncKey(){

App::singleton('App\Models\ResourceServer\IAccessTokenService', AccessTokenServiceStub2::class);

$params = [
'id' => self::$summit->getId(),
];

$response = $this->action(
"GET",
"OAuth2SummitApiController@getQREncKey",
$params,
[],
[],
[],
$this->getAuthHeaders()
);

$content = $response->getContent();
$this->assertResponseStatus(200);
$summit_enc_key = json_decode($content);
self::assertNotNull($summit_enc_key);
}
}
2 changes: 2 additions & 0 deletions tests/ProtectedApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function get($token_value)
ElectionScopes::NominatesCandidates,
ElectionScopes::WriteMyCandidateProfile,
sprintf(SummitScopes::ReadAuditLogs, $url),
sprintf(SummitScopes::ReadSummitsEncKey, $url),
);

return AccessToken::createFromParams(
Expand Down Expand Up @@ -230,6 +231,7 @@ public function get($token_value)
ElectionScopes::NominatesCandidates,
ElectionScopes::WriteMyCandidateProfile,
sprintf(SummitScopes::Allow2PresentationAttendeeVote, $url),
sprintf(SummitScopes::ReadSummitsEncKey, $url),
);

return AccessToken::createFromParams(
Expand Down