Skip to content
Merged
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
19 changes: 19 additions & 0 deletions app/Http/Controllers/Api/OAuth2/OAuth2UserApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ public function get($id)
}
}

/**
* @param $id
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function getV2($id)
{
return $this->processRequest(function() use($id) {
$user = $this->repository->getById(intval($id));
if (is_null($user)) {
throw new EntityNotFoundException();
}
return $this->ok(SerializerRegistry::getInstance()
->getSerializer($user, SerializerRegistry::SerializerType_Private)
->serialize(
Request::input("expand", '')
));
});
}

/**
* @param $user_id
* @return JsonResponse|mixed
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Kernel extends HttpKernel
'ssl',
'oauth2.endpoint',
],
'api_v2' => [
'ssl',
'oauth2.endpoint',
],
];

/**
Expand Down
5 changes: 5 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ protected function mapApiRoutes()
->namespace('App\Http\Controllers\Api\OAuth2')
->prefix('api/v1')
->group(base_path('routes/api.php'));

Route::middleware('api_v2')
->namespace('App\Http\Controllers\Api\OAuth2')
->prefix('api/v2')
->group(base_path('routes/api_v2.php'));
}

}
53 changes: 53 additions & 0 deletions database/migrations/Version20250807173401.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php namespace Database\Migrations;
/**
* 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 App\libs\Auth\Models\IGroupSlugs;
use App\libs\OAuth2\IGroupScopes;
use Auth\Group;
use Database\Seeders\SeedUtils;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class Version20250807173401
* @package Database\Migrations
*/
class Version20250807173401 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema):void
{
SeedUtils::seedApiEndpoints('users', [
[
'name' => 'get-user-by-id-v2',
'active' => true,
'route' => '/api/v2/users/{id}',
'http_method' => 'GET',
'scopes' => [
\App\libs\OAuth2\IUserScopes::ReadAll
],
],
]);
}

/**
* @param Schema $schema
*/
public function down(Schema $schema):void
{

}
}
9 changes: 9 additions & 0 deletions database/seeds/ApiEndpointSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ private function seedUsersEndpoints()
\App\libs\OAuth2\IUserScopes::ReadAll
],
],
[
'name' => 'get-user-by-id-v2',
'active' => true,
'route' => '/api/v2/users/{id}',
'http_method' => 'GET',
'scopes' => [
\App\libs\OAuth2\IUserScopes::ReadAll
],
],
[
'name' => 'update-my-user',
'active' => true,
Expand Down
32 changes: 32 additions & 0 deletions routes/api_v2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* 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 Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| OAuth2 Protected API
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['prefix' => 'users'], function () {
Route::group(['prefix' => '{id}'], function () {
Route::get('', ['middleware' => 'service.account', 'uses' => 'OAuth2UserApiController@getV2']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Class OAuth2UserServiceApiTest
*/
final class OAuth2UserServiceApiTest extends OAuth2ProtectedServiceAppApiTestCase {
final class OAuth2UserApiTest extends OAuth2ProtectedServiceAppApiTestCase {

public function testUpdateMe(){

Expand Down Expand Up @@ -72,6 +72,53 @@ public function testGetInfo(){
$user_info = json_decode($content);
}

public function testGetUserByIdV1(){
$repo = EntityManager::getRepository(User::class);
$user = $repo->getAll()[0];

$params = [
'id' => $user->getId()
];

$response = $this->action(
"GET",
"Api\OAuth2\OAuth2UserApiController@get",
$params,
[],
[],
[],
array("HTTP_Authorization" => " Bearer " .$this->access_token));

$content = $response->getContent();
$this->assertResponseStatus(200);
$user = json_decode($content);
$this->assertNotNull($user);
}

public function testGetUserByIdV2(){
$repo = EntityManager::getRepository(User::class);
$user = $repo->getAll()[0];

$params = [
'id' => $user->getId(),
'expand' => 'groups'
];

$response = $this->action(
"GET",
"Api\OAuth2\OAuth2UserApiController@getV2",
$params,
[],
[],
[],
array("HTTP_Authorization" => " Bearer " .$this->access_token_service_app_type));

$content = $response->getContent();
$this->assertResponseStatus(200);
$user = json_decode($content);
$this->assertNotNull($user);
}

public function testGetInfoCORS(){
$response = $this->action("OPTIONS", "Api\OAuth2\OAuth2UserApiController@me",
[],
Expand Down
Loading