Skip to content

Commit

Permalink
Compatibility with Bagisto version 2.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ghermans committed Nov 10, 2024
1 parent 61a5d5f commit 691e8b6
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 169 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [1.2] - 10-11-2024
- Updated compatibility with Bagisto version 2.2.3

## [1.1] - 3-3-2024
- Updated compatibility with Bagisto version 2.1.1

Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}
],
"require": {
"laravel/prompts": "^0.1.12",
"laravel/socialite": "^5.0",
"socialiteproviders/microsoft-azure": "^5.1"
},
Expand Down
13 changes: 6 additions & 7 deletions src/Config/services.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php


return [
'azure' => [
'client_id' => env('AZURE_CLIENT_ID'),
'azure' => [
'client_id' => env('AZURE_CLIENT_ID'),
'client_secret' => env('AZURE_CLIENT_SECRET'),
'redirect' => env('AZURE_REDIRECT_URL'),
'tenant' => env('AZURE_TENANT_ID')
]
];
'redirect' => env('AZURE_REDIRECT_URL'),
'tenant' => env('AZURE_TENANT_ID'),
],
];
42 changes: 16 additions & 26 deletions src/Console/Commands/ConfigureAzure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,25 @@

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\warning;
use function Laravel\Prompts\text;
use function Laravel\Prompts\warning;

class ConfigureAzure extends Command
{
protected $signature = 'azure:configure';

protected $description = 'Configure Azure environment variables';

public function handle()
{
if (!File::exists(base_path('vendor/socialiteproviders/microsoft-azure/Provider.php'))) {
warning('Required Socialite Provider (socialiteproviders/microsoft-azure) is missing.');
$installProvider = confirm('Install the required provider now? (Press enter to proceed)', true);

if ($installProvider) {
exec('composer require socialiteproviders/microsoft-azure');
} else {
return;
}
}

{
info('Welcome to the Microsoft Azure SSO configuration wizard');
info('Please verify your Azure app registration and redirect URI is set: ' . route('azure.callback'));
warning('Please add the redirect URI inside your Azure app registration: '.route('azure.callback'));

if ($this->keysExist()) {
warning('Existing Azure configuration keys found');
$overwrite = confirm('Continuing will overwrite current settings. Do you want to proceed?', false);

if (!$overwrite) {
if (! $overwrite) {
return;
}
}
Expand All @@ -49,6 +39,13 @@ public function handle()

$this->updateEnvFile('AZURE_CLIENT_ID', $clientId);

$tenantId = text(
label: 'Please enter your tenant ID',
required: true
);

$this->updateEnvFile('AZURE_TENANT_ID', $tenantId);

$clientSecret = text(
label: 'Please enter your client Secret',
required: true
Expand All @@ -58,20 +55,13 @@ public function handle()

$this->updateEnvFile('AZURE_REDIRECT_URL', route('azure.callback'));

$tenantId = text(
label: 'Please enter your tenant ID',
required: true
);

$this->updateEnvFile('AZURE_TENANT_ID', $tenantId);

Artisan::call('optimize');

Artisan::call('vendor:publish', [
'--provider' => "Bagisto\AzureAuth\Providers\AzureAuthServiceProvider",
'--force' => true
'--force' => true,
]);

Artisan::call('optimize');

info('Azure SSO configuration completed successfully.');
}

Expand All @@ -92,7 +82,7 @@ protected function updateEnvFile($key, $value)
if (Str::contains($envContent, "{$key}=")) {
$envContent = preg_replace("/{$key}=.*/", "{$key}=\"{$value}\"", $envContent);
} else {
$envContent .= PHP_EOL . "{$key}=\"{$value}\"";
$envContent .= PHP_EOL."{$key}=\"{$value}\"";
}

File::put($envFilePath, $envContent);
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/AzureConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static function isConfigured()
$redirect = config('services.azure.redirect');
$tenant = config('services.azure.tenant');

return !empty($client_id) && !empty($client_secret) && !empty($redirect) && !empty($tenant);
return ! empty($client_id) && ! empty($client_secret) && ! empty($redirect) && ! empty($tenant);
}
}
27 changes: 12 additions & 15 deletions src/Http/Controllers/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use App\Http\Controllers\Controller;
use Bagisto\AzureAuth\Helpers\AzureConfigHelper;

use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;

use Webkul\User\Repositories\AdminRepository;

class SessionController extends Controller
Expand All @@ -20,8 +18,7 @@ class SessionController extends Controller
*/
public function __construct(
protected AdminRepository $adminRepository
) {
}
) {}

/**
* Redirect the user to the Azure authentication page.
Expand All @@ -30,7 +27,7 @@ public function __construct(
*/
public function redirectToAzure()
{
if (!AzureConfigHelper::isConfigured()) {
if (! AzureConfigHelper::isConfigured()) {
return view('azure-auth::errors.config');
}

Expand All @@ -45,23 +42,23 @@ public function redirectToAzure()
public function handleCallback()
{
try {
if (!AzureConfigHelper::isConfigured()) {
if (! AzureConfigHelper::isConfigured()) {
return view('azure-auth::errors.config');
}

$user = Socialite::driver('azure')->user();

$localUser = $this->adminRepository->where('email', $user->getEmail())->first();

if (!$localUser) {
$randomPass = Str::random(80);
if (! $localUser) {
$randomPass = Str::password(80);

$userData = [
'name' => $user->getName(),
'email' => $user->getEmail(),
'name' => $user->getName(),
'email' => $user->getEmail(),
'password' => bcrypt($randomPass),
'role_id' => 1,
'status' => true,
'role_id' => 1,
'status' => true,
];

$localUser = $this->adminRepository->create($userData);
Expand All @@ -73,7 +70,7 @@ public function handleCallback()
}
}

if (!$localUser || !$localUser->status) {
if (! $localUser || ! $localUser->status) {
session()->flash('warning', trans('admin::app.settings.users.activate-warning'));

auth()->guard('admin')->logout();
Expand All @@ -85,7 +82,7 @@ public function handleCallback()

return redirect()->route('admin.dashboard.index');
} catch (\Exception $e) {
Log::error('Azure Authentication Error: ' . $e->getMessage());
Log::error('Azure Authentication Error: '.$e->getMessage());

return redirect()->route('admin.session.create')->with('warning', __('azure-auth::app.auth-error'));
}
Expand Down
7 changes: 2 additions & 5 deletions src/Providers/AzureAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace Bagisto\AzureAuth\Providers;

use Bagisto\AzureAuth\Console\Commands\ConfigureAzure;
use Bagisto\AzureAuth\Providers\EventServiceProvider;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Http\Kernel;

class AzureAuthServiceProvider extends ServiceProvider
{
Expand All @@ -20,7 +17,7 @@ public function register()
$this->app->register(EventServiceProvider::class);

$this->mergeConfigFrom(
__DIR__ . '/../Config/services.php',
__DIR__.'/../Config/services.php',
'services'
);

Expand All @@ -37,7 +34,7 @@ public function register()
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../Routes/web.php');

$this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'azure-auth');

$this->loadViewsFrom(__DIR__.'/../Resources/views', 'azure-auth');
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'أو',
'sign-in' => 'تسجيل الدخول باستخدام Microsoft',
'auth-error' => 'تعذر التحقق من هويتك باستخدام حساب Microsoft الخاص بك. يرجى المحاولة مرة أخرى.',
'or' => 'أو',
'sign-in' => 'تسجيل الدخول باستخدام Microsoft',
'auth-error' => 'تعذر التحقق من هويتك باستخدام حساب Microsoft الخاص بك. يرجى المحاولة مرة أخرى.',
'config-error' => [
'title' => 'عذرًا! حدث خطأ',
'message' => 'نعتذر عن الإزعاج. يبدو أن Azure SSO لم يتم تكوينه بعد في Bagisto الخاص بك.',
'title' => 'عذرًا! حدث خطأ',
'message' => 'نعتذر عن الإزعاج. يبدو أن Azure SSO لم يتم تكوينه بعد في Bagisto الخاص بك.',
'support' => 'إذا كنت غير متأكد من خطوات التكوين أو تحتاج إلى مساعدة، يرجى الاتصال بفريق الدعم لدينا على <a href=":link" class=":class">:email</a>',
],
];
10 changes: 5 additions & 5 deletions src/Resources/lang/bn/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'অথবা',
'sign-in' => 'মাইক্রোসফট দিয়ে সাইন ইন করুন',
'auth-error' => 'আপনার মাইক্রোসফট অ্যাকাউন্ট দিয়ে প্রমাণীকরণ সম্পন্ন হয়নি। দয়া করে আবার চেষ্টা করুন।',
'or' => 'অথবা',
'sign-in' => 'মাইক্রোসফট দিয়ে সাইন ইন করুন',
'auth-error' => 'আপনার মাইক্রোসফট অ্যাকাউন্ট দিয়ে প্রমাণীকরণ সম্পন্ন হয়নি। দয়া করে আবার চেষ্টা করুন।',
'config-error' => [
'title' => 'ওহো! কিছু ভুল হয়েছে',
'message' => 'আমরা আপনার সহজবান করার জন্য ক্ষমা চাই। এটি মনে হচ্ছে যে, আপনার Bagisto ইনস্ট্যান্সে এখনো Azure SSO কনফিগার হয়নি।',
'title' => 'ওহো! কিছু ভুল হয়েছে',
'message' => 'আমরা আপনার সহজবান করার জন্য ক্ষমা চাই। এটি মনে হচ্ছে যে, আপনার Bagisto ইনস্ট্যান্সে এখনো Azure SSO কনফিগার হয়নি।',
'support' => 'আপনি যদি কনফিগারেশন পদক্ষেপে অসমর্থ হন বা সাহায্য প্রয়োজন হয়, আমাদের সাপোর্ট টীমের সাথে <a href=":link" class=":class">:email</a> যোগাযোগ করুন',
],
];
10 changes: 5 additions & 5 deletions src/Resources/lang/de/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'oder',
'sign-in' => 'Mit Microsoft anmelden',
'auth-error' => 'Anmeldung mit Ihrem Microsoft-Konto nicht möglich. Bitte versuchen Sie es erneut.',
'or' => 'oder',
'sign-in' => 'Mit Microsoft anmelden',
'auth-error' => 'Anmeldung mit Ihrem Microsoft-Konto nicht möglich. Bitte versuchen Sie es erneut.',
'config-error' => [
'title' => 'Hoppla! Etwas ist schiefgegangen',
'message' => 'Wir entschuldigen uns für die Unannehmlichkeiten. Es scheint, dass Azure SSO in Ihrer Bagisto-Instanz noch nicht konfiguriert ist.',
'title' => 'Hoppla! Etwas ist schiefgegangen',
'message' => 'Wir entschuldigen uns für die Unannehmlichkeiten. Es scheint, dass Azure SSO in Ihrer Bagisto-Instanz noch nicht konfiguriert ist.',
'support' => 'Wenn Sie sich bei den Konfigurationsschritten unsicher sind oder Unterstützung benötigen, wenden Sie sich bitte an unser Support-Team unter <a href=":link" class=":class">:email</a>',
],
];
12 changes: 6 additions & 6 deletions src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'or',
'sign-in' => 'Sign in with Microsoft',
'auth-error' => 'Unable to authenticate with your Microsoft account. Please try again.',
'or' => 'or',
'sign-in' => 'Sign in with Microsoft',
'auth-error' => 'Unable to authenticate with your Microsoft account. Please try again.',
'config-error' => [
'title' => 'Oops! Something Went Wrong',
'message' => 'We apologize for the inconvenience. It seems that Azure SSO is not configured yet in your Bagisto instance.',
'title' => 'Oops! Something Went Wrong',
'message' => 'We apologize for the inconvenience. It seems that Azure SSO is not configured yet in your Bagisto instance.',
'support' => 'If you are unsure about the configuration steps or need assistance, reach out to our support team at <a href=":link" class=":class">:email</a>',
],
];
];
10 changes: 5 additions & 5 deletions src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'o',
'sign-in' => 'Iniciar sesión con Microsoft',
'auth-error' => 'No se puede autenticar con su cuenta de Microsoft. Por favor, inténtelo de nuevo.',
'or' => 'o',
'sign-in' => 'Iniciar sesión con Microsoft',
'auth-error' => 'No se puede autenticar con su cuenta de Microsoft. Por favor, inténtelo de nuevo.',
'config-error' => [
'title' => '¡Ups! Algo salió mal',
'message' => 'Pedimos disculpas por las molestias. Parece que Azure SSO aún no está configurado en su instancia de Bagisto.',
'title' => '¡Ups! Algo salió mal',
'message' => 'Pedimos disculpas por las molestias. Parece que Azure SSO aún no está configurado en su instancia de Bagisto.',
'support' => 'Si no está seguro acerca de los pasos de configuración o necesita asistencia, comuníquese con nuestro equipo de soporte en <a href=":link" class=":class">:email</a>',
],
];
10 changes: 5 additions & 5 deletions src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'یا',
'sign-in' => 'ورود با Microsoft',
'auth-error' => 'امکان احراز هویت با حساب کاربری Microsoft شما وجود ندارد. لطفاً دوباره امتحان کنید.',
'or' => 'یا',
'sign-in' => 'ورود با Microsoft',
'auth-error' => 'امکان احراز هویت با حساب کاربری Microsoft شما وجود ندارد. لطفاً دوباره امتحان کنید.',
'config-error' => [
'title' => 'اوه! مشکلی پیش آمد',
'message' => 'از ناشی شدن مشکل پوزش می‌خواهیم. به نظر می‌آید که Azure SSO هنوز در نمونه Bagisto شما پیکربندی نشده است.',
'title' => 'اوه! مشکلی پیش آمد',
'message' => 'از ناشی شدن مشکل پوزش می‌خواهیم. به نظر می‌آید که Azure SSO هنوز در نمونه Bagisto شما پیکربندی نشده است.',
'support' => 'اگر از مراحل پیکربندی اطمینان ندارید یا به کمک نیاز دارید، با تیم پشتیبانی ما تماس بگیرید: <a href=":link" class=":class">:email</a>',
],
];
10 changes: 5 additions & 5 deletions src/Resources/lang/fr/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'ou',
'sign-in' => 'Se connecter avec Microsoft',
'auth-error' => 'Impossible de s\'authentifier avec votre compte Microsoft. Veuillez réessayer.',
'or' => 'ou',
'sign-in' => 'Se connecter avec Microsoft',
'auth-error' => 'Impossible de s\'authentifier avec votre compte Microsoft. Veuillez réessayer.',
'config-error' => [
'title' => 'Oups ! Quelque chose s\'est mal passé',
'message' => 'Nous nous excusons pour la gêne occasionnée. Il semble qu\'Azure SSO ne soit pas encore configuré dans votre instance Bagisto.',
'title' => 'Oups ! Quelque chose s\'est mal passé',
'message' => 'Nous nous excusons pour la gêne occasionnée. Il semble qu\'Azure SSO ne soit pas encore configuré dans votre instance Bagisto.',
'support' => 'Si vous avez des doutes sur les étapes de configuration ou si vous avez besoin d\'assistance, contactez notre équipe de support à l\'adresse suivante : <a href=":link" class=":class">:email</a>',
],
];
10 changes: 5 additions & 5 deletions src/Resources/lang/he/app.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'or' => 'או',
'sign-in' => 'התחבר עם מיקרוסופט',
'auth-error' => 'אין אפשרות לאמת עם החשבון שלך במיקרוסופט. יש לנסות שוב.',
'or' => 'או',
'sign-in' => 'התחבר עם מיקרוסופט',
'auth-error' => 'אין אפשרות לאמת עם החשבון שלך במיקרוסופט. יש לנסות שוב.',
'config-error' => [
'title' => 'אופס! משהו השתבש',
'message' => 'אנו מתנצלים על התקלות. נראה שאין הגדרה של Azure SSO בתצורת ה-Bagisto שלך עדיין.',
'title' => 'אופס! משהו השתבש',
'message' => 'אנו מתנצלים על התקלות. נראה שאין הגדרה של Azure SSO בתצורת ה-Bagisto שלך עדיין.',
'support' => 'אם אינך בטוח לגבי השלבת ההגדרות או זקוק לעזרה, אנא צור קשר עם צוות התמיכה שלנו ב־<a href=":link" class=":class">:email</a>',
],
];
Loading

0 comments on commit 691e8b6

Please sign in to comment.