Skip to content

A free open source IT asset/license management system

Fixed typo

snipe99c3ac56e9a0
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index 9a9817d17f..276719942e 100644
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -1236,4 +1236,52 @@ class SettingsController extends Controller
{
return view('settings.logins');
}
+
+ /**
+ * Revoke an OAuth client from the admin OAuth settings page.
+ */
+ public function revokeOAuthClient(string $client): RedirectResponse
+ {
+ $oauthClient = DB::table('oauth_clients')
+ ->where('id', $client)
+ ->first();
+
+ if ($oauthClient === null) {
+ return redirect()
+ ->to(route('settings.oauth.index').'#oauth-clients')
+ ->with('error', trans('admin/settings/message.oauth.client_not_found'));
+ }
+
+ DB::table('oauth_clients')
+ ->where('id', $client)
+ ->update(['revoked' => true]);
+
+ return redirect()
+ ->to(route('settings.oauth.index').'#oauth-clients')
+ ->with('success', trans('admin/settings/message.oauth.client_revoked'));
+ }
+
+ /**
+ * Unrevoke an OAuth client from the admin OAuth settings page.
+ */
+ public function unrevokeOAuthClient(string $client): RedirectResponse
+ {
+ $oauthClient = DB::table('oauth_clients')
+ ->where('id', $client)
+ ->first();
+
+ if ($oauthClient === null) {
+ return redirect()
+ ->to(route('settings.oauth.index').'#oauth-clients')
+ ->with('error', trans('admin/settings/message.oauth.client_not_found'));
+ }
+
+ DB::table('oauth_clients')
+ ->where('id', $client)
+ ->update(['revoked' => false]);
+
+ return redirect()
+ ->to(route('settings.oauth.index').'#oauth-clients')
+ ->with('success', trans('admin/settings/message.oauth.client_unrevoked'));
+ }
}
diff --git a/app/Livewire/OauthClients.php b/app/Livewire/OauthClients.php
index aea639c878..c7072f7fdf 100644
--- a/app/Livewire/OauthClients.php
+++ b/app/Livewire/OauthClients.php
@@ -45,7 +45,9 @@ class OauthClients extends Component
{
$clients = collect();
if ($this->showOauthClients()) {
- $clients = app(ClientRepository::class);
+ $clients = Client::query()
+ ->orderByDesc('created_at')
+ ->get();
if ($clients->isNotEmpty()) {
$tokenCountsByClientId = DB::table('oauth_access_tokens')
@@ -130,7 +132,6 @@ class OauthClients extends Component
{
$revokedTokenCount = DB::table('oauth_access_tokens')
->where('client_id', $clientId)
- ->where('user_id', auth()->id())
->where('revoked', false)
->update(['revoked' => true]);
diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php
index 010c0598b5..e16e3a2972 100644
--- a/resources/lang/en-US/admin/settings/general.php
+++ b/resources/lang/en-US/admin/settings/general.php
@@ -333,6 +333,10 @@ return [
'oauth_redirect_url' => 'Redirect URL',
'oauth_name_help' => ' Something your users will recognize and trust.',
'oauth_scopes' => 'Scopes',
+ 'oauth_client_type' => 'Client Type',
+ 'oauth_client_type_oauth' => 'OAuth Client',
+ 'oauth_client_type_personal_access' => 'Personal Access Client',
+ 'oauth_client_type_password_grant' => 'Password Grant Client',
'oauth_associated_token_count' => 'Token Count',
'oauth_callback_url' => 'Your application authorization callback URL.',
'oauth_personal_access_tokens' => 'User API Tokens (Personal Access Tokens)',
diff --git a/resources/lang/en-US/admin/settings/message.php b/resources/lang/en-US/admin/settings/message.php
index bf26e39bc5..9b7ad82de5 100644
--- a/resources/lang/en-US/admin/settings/message.php
+++ b/resources/lang/en-US/admin/settings/message.php
@@ -65,6 +65,9 @@ return [
'client_created' => 'OAuth client created successfully.',
'client_updated' => 'OAuth client updated successfully.',
'client_deleted' => 'OAuth client deleted successfully.',
+ 'client_revoked' => 'OAuth client revoked successfully.',
+ 'client_unrevoked' => 'OAuth client reinstated successfully.',
+ 'client_not_found' => 'That OAuth client could not be found.',
'token_deleted' => 'Token revoked successfully.',
'client_delete_denied' => 'You are not authorized to delete this client.',
'client_edit_denied' => 'You are not authorized to edit this client.',
diff --git a/resources/views/livewire/oauth-clients.blade.php b/resources/views/livewire/oauth-clients.blade.php
index 04e902dff9..3ad1223f9e 100644
--- a/resources/views/livewire/oauth-clients.blade.php
+++ b/resources/views/livewire/oauth-clients.blade.php
@@ -29,6 +29,8 @@
<tr>
<th data-field="id" data-sortable="true">{{ trans('general.id') }}</th>
<th data-field="name" data-sortable="true">{{ trans('general.name') }}</th>
+ <th data-field="client_type" data-sortable="true">{{ trans('admin/settings/general.oauth_client_type') }}</th>
+ <th data-field="revoked" data-sortable="true">{{ trans('general.status') }}</th>
<th data-field="redirect" data-sortable="true">{{ trans('admin/settings/general.oauth_redirect_url') }}</th>
<th data-field="secret" data-sortable="true">{{ trans('admin/settings/general.oauth_secret') }}</th>
<th data-field="associated_token_count" data-sortable="true">{{ trans('admin/settings/general.oauth_associated_token_count') }}</th>
@@ -41,9 +43,29 @@
</thead>
<tbody>
@foreach($clients as $client)
+ @php
+ $isPersonalAccessClient = (int) $client->personal_access_client === 1;
+ $isPasswordGrantClient = (int) $client->password_client === 1;
+ $isRevokedClient = (int) $client->revoked === 1;
+ $clientTypeLabel = $isPersonalAccessClient
+ ? trans('admin/settings/general.oauth_client_type_personal_access')
+ : ($isPasswordGrantClient
+ ? trans('admin/settings/general.oauth_client_type_password_grant')
+ : trans('admin/settings/general.oauth_client_type_oauth'));
+ @endphp
<tr>
<td>{{ $client->id }}</td>
<td>{{ $client->name }}</td>
+ <td>
+ <span class="label label-info">{{ $clientTypeLabel }}</span>
+ </td>
+ <td>
+ @if($isRevokedClient)
+ <span class="label label-danger">{{ trans('admin/settings/general.oauth_token_status_revoked') }}</span>
+ @else
+ <span class="label label-success">{{ trans('admin/settings/general.oauth_token_status_active') }}</span>
+ @endif
+ </td>
<td><code>{{ $client->redirect }}</code></td>
<td><code>{{ $client->secret }}</code></td>
<td>{{ $client->associated_token_count ?? 0 }}</td>
@@ -53,14 +75,27 @@
{{ $client->updated_at ? Helper::getFormattedDateObject($client->updated_at, 'datetime', false) : '' }}
@endif
</td>
- <td class="text-right">
- <a class="action-link btn btn-sm btn-warning" wire:click="editClient('{{ $client->id }}')" onclick="$('#modal-edit-client').modal('show');">
+ <td class="text-right" style="white-space: nowrap;">
+ @if($isRevokedClient)
+ <form method="POST" action="{{ route('settings.oauth.clients.unrevoke', ['client' => $client->id]) }}" style="display: inline;">
+ @csrf
+ <button type="submit" class="btn btn-sm btn-default text-success" data-tooltip="true" title="{{ trans('admin/settings/general.oauth_unrevoke') }}">
+ <i class="fa-solid fa-toggle-off"></i>
+ </button>
+ </form>
+ @else
+ <form method="POST" action="{{ route('settings.oauth.clients.revoke', ['client' => $client->id]) }}" style="display: inline;">
+ @csrf
+ <button type="submit" class="btn btn-sm btn-default text-danger" data-tooltip="true" title="{{ trans('admin/settings/general.oauth_revoke') }}">
+ <i class="fa-solid fa-toggle-on"></i>
+ </button>
+ </form>
+ @endif
+ <a class="action-link btn btn-sm btn-warning" wire:click="editClient('{{ $client->id }}')" onclick="$('#modal-edit-client').modal('show');" data-tooltip="true" title="{{ trans('general.update') }}">
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
- <span class="sr-only">{{ trans('general.update') }}</span>
</a>
- <a class="action-link btn btn-danger btn-sm" wire:click="deleteClient('{{ $client->id }}')">
+ <a class="action-link btn btn-sm btn-danger" wire:click="deleteClient('{{ $client->id }}')" data-tooltip="true" title="{{ trans('general.delete') }}">
<i class="fas fa-trash" aria-hidden="true"></i>
- <span class="sr-only">{{ trans('general.delete') }}</span>
</a>
</td>
</tr>
@@ -72,7 +107,7 @@
@if ($this->showAuthorizedApplications())
@if($authorizedApplications->count() === 0)
- <p>{{ trans('admin/settings/general.oauth_no_applications) }}</p>
+ <p>{{ trans('admin/settings/general.oauth_no_clients') }}</p>
@else
<div id="AuthorizedAppsToolbar" class="pull-left" style="min-width: 280px; padding-top: 10px;"></div>
<table
diff --git a/routes/web.php b/routes/web.php
index b0a0d4b915..2709f422aa 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -235,6 +235,12 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser
Route::post('oauth/tokens/{token}/unrevoke', [SettingsController::class, 'unrevokePersonalAccessToken'])
->name('settings.oauth.tokens.unrevoke');
+ Route::post('oauth/clients/{client}/revoke', [SettingsController::class, 'revokeOAuthClient'])
+ ->name('settings.oauth.clients.revoke');
+
+ Route::post('oauth/clients/{client}/unrevoke', [SettingsController::class, 'unrevokeOAuthClient'])
+ ->name('settings.oauth.clients.unrevoke');
+
Route::get('google', [SettingsController::class, 'getGoogleLoginSettings'])
->name('settings.google.index')
->breadcrumbs(fn (Trail $trail) => $trail->parent('settings.index')
diff --git a/tests/Feature/Settings/OauthSettingsTest.php b/tests/Feature/Settings/OauthSettingsTest.php
index b75fc07003..ea24b8d5df 100644
--- a/tests/Feature/Settings/OauthSettingsTest.php
+++ b/tests/Feature/Settings/OauthSettingsTest.php
@@ -277,7 +277,6 @@ class OauthSettingsTest extends TestCase
$this->actingAs($superuser)
->get(route('settings.oauth.index'))
->assertOk()
- ->assertDontSee(trans('admin/settings/general.oauth_associated_token_count'))
->assertSee('Active Client Creator')
->assertSee(route('users.show', $activeCreator))
->assertSee('<del>Deleted Client Creator</del>', false)
@@ -318,6 +317,42 @@ class OauthSettingsTest extends TestCase
'updated_at' => now(),
]);
+ DB::table('oauth_clients')->insert([
+ 'user_id' => null,
+ 'name' => 'Personal Access Legacy Client',
+ 'secret' => 'secret',
+ 'redirect' => 'http://localhost/callback',
+ 'personal_access_client' => 1,
+ 'password_client' => 0,
+ 'revoked' => 0,
+ 'created_at' => now(),
+ 'updated_at' => now(),
+ ]);
+
+ DB::table('oauth_clients')->insert([
+ 'user_id' => null,
+ 'name' => 'Password Grant Legacy Client',
+ 'secret' => 'secret',
+ 'redirect' => 'http://localhost/callback',
+ 'personal_access_client' => 0,
+ 'password_client' => 1,
+ 'revoked' => 0,
+ 'created_at' => now(),
+ 'updated_at' => now(),
+ ]);
+
+ DB::table('oauth_clients')->insert([
+ 'user_id' => null,
+ 'name' => 'Revoked OAuth Legacy Client',
+ 'secret' => 'secret',
+ 'redirect' => 'http://localhost/callback',
+ 'personal_access_client' => 0,
+ 'password_client' => 0,
+ 'revoked' => 1,
+ 'created_at' => now(),
+ 'updated_at' => now(),
+ ]);
+
DB::table('oauth_access_tokens')->insert([
[
'id' => 'owned-client-token-1',
@@ -358,8 +393,17 @@ class OauthSettingsTest extends TestCase
->get(route('settings.oauth.index'))
->assertOk()
->assertSee(trans('admin/settings/general.oauth_associated_token_count'))
+ ->assertSee(trans('admin/settings/general.oauth_client_type'))
->assertSee('Owned OAuth Client')
+ ->assertSee('Personal Access Legacy Client')
+ ->assertSee('Password Grant Legacy Client')
+ ->assertSee('Revoked OAuth Legacy Client')
+ ->assertSee(trans('admin/settings/general.oauth_client_type_oauth'))
+ ->assertSee(trans('admin/settings/general.oauth_client_type_personal_access'))
+ ->assertSee(trans('admin/settings/general.oauth_client_type_password_grant'))
+ ->assertSee(trans('admin/settings/general.oauth_token_status_revoked'))
->assertSee('data-field="associated_token_count"', false)
+ ->assertSee('data-field="client_type"', false)
->assertSeeInOrder(['Owned OAuth Client', '<td>2</td>'], false)
->assertDontSee('Other Client Token One');
}