mirror of
https://github.com/brufdev/many-notes.git
synced 2025-12-17 08:34:58 -06:00
Rename OAuthProviders enum to OAuthProvider for consistency
This commit is contained in:
@@ -4,19 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
|
||||
final readonly class GetAvailableOAuthProviders
|
||||
{
|
||||
/**
|
||||
* @return array<int, OAuthProviders>
|
||||
* @return array<int, OAuthProvider>
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
return array_filter(
|
||||
OAuthProviders::cases(),
|
||||
OAuthProvider::cases(),
|
||||
/** @phpstan-ignore-next-line */
|
||||
fn(OAuthProviders $provider): ?string => config("services.{$provider->value}.client_id"),
|
||||
fn(OAuthProvider $provider): ?string => config("services.{$provider->value}.client_id"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
|
||||
final readonly class GetOAuthPostLogoutRedirectUri
|
||||
{
|
||||
@@ -13,7 +13,7 @@ final readonly class GetOAuthPostLogoutRedirectUri
|
||||
$providers = new GetAvailableOAuthProviders()->handle();
|
||||
$provider = current($providers);
|
||||
|
||||
if (!$provider instanceof OAuthProviders) {
|
||||
if (!$provider instanceof OAuthProvider) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum OAuthProviders: string
|
||||
enum OAuthProvider: string
|
||||
{
|
||||
case Authelia = 'authelia';
|
||||
case Authentik = 'authentik';
|
||||
@@ -6,7 +6,7 @@ namespace App\Livewire\Auth;
|
||||
|
||||
use App\Actions\GetAvailableOAuthProviders;
|
||||
use App\Actions\IsLocalAuthEnabled;
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
use App\Livewire\Forms\LoginForm;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
@@ -20,7 +20,7 @@ final class Login extends Component
|
||||
{
|
||||
public LoginForm $form;
|
||||
|
||||
/** @var array<int, OAuthProviders> */
|
||||
/** @var array<int, OAuthProvider> */
|
||||
public array $providers;
|
||||
|
||||
public function mount(): void
|
||||
@@ -29,7 +29,7 @@ final class Login extends Component
|
||||
|
||||
if ($this->providers !== [] && !new IsLocalAuthEnabled()->handle()) {
|
||||
try {
|
||||
/** @var OAuthProviders $provider */
|
||||
/** @var OAuthProvider $provider */
|
||||
$provider = current($this->providers);
|
||||
$this->redirect(Socialite::driver($provider->value)->redirect()->getTargetUrl());
|
||||
} catch (Throwable) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\GetAvailableOAuthProviders;
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
use App\Http\Controllers\FileController;
|
||||
use App\Livewire\Auth\ForgotPassword;
|
||||
use App\Livewire\Auth\Login;
|
||||
@@ -42,7 +42,7 @@ Route::middleware(['guest', 'throttle'])->group(function (): void {
|
||||
|
||||
Route::prefix('oauth')->group(function (): void {
|
||||
$providers = implode('|', array_map(
|
||||
fn(OAuthProviders $provider): string => $provider->value,
|
||||
fn(OAuthProvider $provider): string => $provider->value,
|
||||
new GetAvailableOAuthProviders()->handle(),
|
||||
));
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\GetAvailableOAuthProviders;
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
use App\Livewire\Auth\OAuthLoginCallback;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
@@ -27,7 +27,7 @@ it('successfully authenticates a registered user', function (): void {
|
||||
$provider->shouldReceive('user')->andReturn($abstractUser);
|
||||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLoginCallback::class, ['provider' => 'github'])
|
||||
->assertRedirect(route('vaults.show', ['vaultId' => 1]));
|
||||
@@ -48,7 +48,7 @@ it('successfully authenticates a non-registered user', function (): void {
|
||||
$provider->shouldReceive('user')->andReturn($abstractUser);
|
||||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLoginCallback::class, ['provider' => 'github'])
|
||||
->assertRedirect(route('vaults.index'));
|
||||
@@ -58,7 +58,7 @@ it('fails to authenticate user', function (): void {
|
||||
$provider = Mockery::mock(Provider::class);
|
||||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLoginCallback::class, ['provider' => 'github'])
|
||||
->assertRedirect(route('login'));
|
||||
@@ -77,7 +77,7 @@ it('fails to authenticate user without email', function (): void {
|
||||
$provider->shouldReceive('user')->andReturn($abstractUser);
|
||||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLoginCallback::class, ['provider' => 'github'])
|
||||
->assertRedirect(route('login'));
|
||||
@@ -100,7 +100,7 @@ it('fails to authenticate a non-registered user when registration is disabled',
|
||||
$provider->shouldReceive('user')->andReturn($abstractUser);
|
||||
Socialite::shouldReceive('driver')->with('github')->andReturn($provider);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLoginCallback::class, ['provider' => 'github'])
|
||||
->assertRedirect(route('login'));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\GetAvailableOAuthProviders;
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
use App\Livewire\Auth\OAuthLogin;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use Livewire\Livewire;
|
||||
@@ -12,7 +12,7 @@ it('redirects to the provider url', function (): void {
|
||||
$targetUrl = 'https://github.com/login/oauth/authorize';
|
||||
Socialite::shouldReceive('driver->redirect->getTargetUrl')->andReturn($targetUrl);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLogin::class, ['provider' => 'github'])
|
||||
->assertRedirect($targetUrl);
|
||||
@@ -21,7 +21,7 @@ it('redirects to the provider url', function (): void {
|
||||
it('fails redirecting to the provider url', function (): void {
|
||||
Socialite::shouldReceive('driver->redirect->getTargetUrl')->andThrowExceptions([new Exception()]);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(OAuthLogin::class, ['provider' => 'github'])
|
||||
->assertStatus(404);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\GetAvailableOAuthProviders;
|
||||
use App\Enums\OAuthProviders;
|
||||
use App\Enums\OAuthProvider;
|
||||
use App\Livewire\Auth\Login;
|
||||
use App\Livewire\Layout\UserMenu;
|
||||
use App\Models\User;
|
||||
@@ -23,7 +23,7 @@ it('redirects the user to the OAuth authentication page', function (): void {
|
||||
$targetUrl = 'https://github.com/login/oauth/authorize';
|
||||
Socialite::shouldReceive('driver->redirect->getTargetUrl')->andReturn($targetUrl);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(Login::class)
|
||||
->assertRedirect($targetUrl);
|
||||
@@ -32,7 +32,7 @@ it('redirects the user to the OAuth authentication page', function (): void {
|
||||
it('fails to redirect the user to the provider URL', function (): void {
|
||||
Socialite::shouldReceive('driver->redirect->getTargetUrl')->andThrowExceptions([new Exception()]);
|
||||
$availableProviders = Mockery::mock(new GetAvailableOAuthProviders());
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProviders::GitHub]);
|
||||
$availableProviders->shouldReceive('handle')->andReturn([OAuthProvider::GitHub]);
|
||||
|
||||
Livewire::test(Login::class, ['provider' => 'github'])
|
||||
->assertStatus(404);
|
||||
|
||||
Reference in New Issue
Block a user