From c52b48c3838c7468cba784bc6aa8ae0098de4e58 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:14:28 -0700 Subject: [PATCH 01/15] Google oauth login Signed-off-by: snipe --- .env.example | 9 ++ app/Http/Controllers/GoogleAuthController.php | 57 +++++++ composer.json | 1 + composer.lock | 149 +++++++++++++++++- config/app.php | 14 +- config/services.php | 3 + resources/lang/en/auth/general.php | 4 +- resources/views/auth/login.blade.php | 14 +- routes/web.php | 6 +- 9 files changed, 247 insertions(+), 10 deletions(-) create mode 100644 app/Http/Controllers/GoogleAuthController.php diff --git a/.env.example b/.env.example index fbf5c4cfff..08baf822f5 100644 --- a/.env.example +++ b/.env.example @@ -175,6 +175,15 @@ REQUIRE_SAML=false API_THROTTLE_PER_MINUTE=120 CSV_ESCAPE_FORMULAS=true + +# -------------------------------------------- +# OPTIONAL: GOOGLE LOGIN +# -------------------------------------------- +ENABLE_GOOGLE_LOGIN=false +GOOGLE_CLIENT_ID=null +GOOGLE_CLIENT_SECRET=null +GOOGLE_REDIRECT_URL=null + # -------------------------------------------- # OPTIONAL: HASHING # -------------------------------------------- diff --git a/app/Http/Controllers/GoogleAuthController.php b/app/Http/Controllers/GoogleAuthController.php new file mode 100644 index 0000000000..b24a3a5b25 --- /dev/null +++ b/app/Http/Controllers/GoogleAuthController.php @@ -0,0 +1,57 @@ +redirect(); + } + + public function handleGoogleCallback() + { + try { + $socialUser = Socialite::driver('google')->user(); + } catch (InvalidStateException $exception) { + + return redirect()->route('login') + ->withErrors( + [ + 'email' => [ + __('Google Login failed, please try again.'), + ], + ] + ); + } + + + $user = User::where('email', $socialUser->getEmail())->first(); + + + if ($user) { + $user->update([ + 'avatar' => $socialUser->avatar, + ]); + + Auth::login($user, true); + return redirect()->route('setup.done'); + } + + return redirect()->route('login') + ->withErrors( + [ + 'email' => [ + trans('admin/users/message.user_not_found'), + ], + ] + ); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index a66aa22df0..165a4a08f6 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "laravel/helpers": "^1.4", "laravel/passport": "^10.1", "laravel/slack-notification-channel": "^2.3", + "laravel/socialite": "^5.6", "laravel/tinker": "^2.6", "laravel/ui": "^3.3", "laravelcollective/html": "^6.2", diff --git a/composer.lock b/composer.lock index 620c7c6855..1ef75690aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0444af6de1d16a70c7e5520db745170", + "content-hash": "4c82b2e171fb02a3ef024906db5d74c9", "packages": [ { "name": "alek13/slack", @@ -3605,6 +3605,75 @@ }, "time": "2022-01-12T18:07:54+00:00" }, + { + "name": "laravel/socialite", + "version": "v5.6.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/socialite.git", + "reference": "a14a177f2cc71d8add71e2b19e00800e83bdda09" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/socialite/zipball/a14a177f2cc71d8add71e2b19e00800e83bdda09", + "reference": "a14a177f2cc71d8add71e2b19e00800e83bdda09", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "illuminate/contracts": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/http": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0", + "league/oauth1-client": "^1.10.1", + "php": "^7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0", + "phpunit/phpunit": "^8.0|^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Socialite\\SocialiteServiceProvider" + ], + "aliases": { + "Socialite": "Laravel\\Socialite\\Facades\\Socialite" + } + } + }, + "autoload": { + "psr-4": { + "Laravel\\Socialite\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.", + "homepage": "https://laravel.com", + "keywords": [ + "laravel", + "oauth" + ], + "support": { + "issues": "https://github.com/laravel/socialite/issues", + "source": "https://github.com/laravel/socialite" + }, + "time": "2023-01-20T15:42:35+00:00" + }, { "name": "laravel/tinker", "version": "v2.7.2", @@ -4534,6 +4603,82 @@ ], "time": "2022-04-17T13:12:02+00:00" }, + { + "name": "league/oauth1-client", + "version": "v1.10.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/oauth1-client.git", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/d6365b901b5c287dd41f143033315e2f777e1167", + "reference": "d6365b901b5c287dd41f143033315e2f777e1167", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-openssl": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "guzzlehttp/psr7": "^1.7|^2.0", + "php": ">=7.1||>=8.0" + }, + "require-dev": { + "ext-simplexml": "*", + "friendsofphp/php-cs-fixer": "^2.17", + "mockery/mockery": "^1.3.3", + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5||9.5" + }, + "suggest": { + "ext-simplexml": "For decoding XML-based responses." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev", + "dev-develop": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\OAuth1\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Corlett", + "email": "bencorlett@me.com", + "homepage": "http://www.webcomm.com.au", + "role": "Developer" + } + ], + "description": "OAuth 1.0 Client Library", + "keywords": [ + "Authentication", + "SSO", + "authorization", + "bitbucket", + "identity", + "idp", + "oauth", + "oauth1", + "single sign on", + "trello", + "tumblr", + "twitter" + ], + "support": { + "issues": "https://github.com/thephpleague/oauth1-client/issues", + "source": "https://github.com/thephpleague/oauth1-client/tree/v1.10.1" + }, + "time": "2022-04-15T14:02:14+00:00" + }, { "name": "league/oauth2-server", "version": "8.3.5", @@ -16425,5 +16570,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.0.0" } diff --git a/config/app.php b/config/app.php index 8833ea2ae7..2913bdc273 100755 --- a/config/app.php +++ b/config/app.php @@ -216,7 +216,17 @@ return [ */ 'require_saml' => env('REQUIRE_SAML', false), - + + + /* + |-------------------------------------------------------------------------- + | Enable Google Login + |-------------------------------------------------------------------------- + */ + + 'google_login' => env('ENABLE_GOOGLE_LOGIN', false), + + /* |-------------------------------------------------------------------------- | Demo Mode Lockdown @@ -294,6 +304,7 @@ return [ Laravel\Tinker\TinkerServiceProvider::class, Unicodeveloper\DumbPassword\DumbPasswordServiceProvider::class, Eduardokum\LaravelMailAutoEmbed\ServiceProvider::class, + Laravel\Socialite\SocialiteServiceProvider::class, /* * Application Service Providers... @@ -366,6 +377,7 @@ return [ 'Image' => Intervention\Image\ImageServiceProvider::class, 'Carbon' => Carbon\Carbon::class, 'Helper' => App\Helpers\Helper::class, // makes it much easier to use 'Helper::blah' in blades (which is where we usually use this) + 'Socialite' => Laravel\Socialite\Facades\Socialite::class, ], diff --git a/config/services.php b/config/services.php index de8c4ed71a..a0f25664f6 100644 --- a/config/services.php +++ b/config/services.php @@ -51,6 +51,9 @@ return [ 'google' => [ 'maps_api_key' => env('GOOGLE_MAPS_API'), + 'client_id' => env('GOOGLE_CLIENT_ID'), + 'client_secret' => env('GOOGLE_CLIENT_SECRET'), + 'redirect' => env('GOOGLE_REDIRECT_URL'), ], ]; diff --git a/resources/lang/en/auth/general.php b/resources/lang/en/auth/general.php index 78b6780927..a0914b6334 100644 --- a/resources/lang/en/auth/general.php +++ b/resources/lang/en/auth/general.php @@ -12,5 +12,7 @@ return [ 'remember_me' => 'Remember Me', 'username_help_top' => 'Enter your username to be emailed a password reset link.', 'username_help_bottom' => 'Your username and email address may be the same, but may not be, depending on your configuration. If you cannot remember your username, contact your administrator.

Usernames without an associated email address will not be emailed a password reset link. ', - ]; + 'google_login' => 'Login via Google', + +]; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 330d7bf503..730afae833 100755 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -64,7 +64,7 @@ @if (!config('app.require_saml') && $snipeSettings->saml_enabled) -
+
diff --git a/routes/web.php b/routes/web.php index 39c66d35d8..f809f5a3e3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -453,8 +453,6 @@ Route::group(['middleware' => 'web'], function () { [LoginController::class, 'postTwoFactorAuth'] ); - - Route::post( 'password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'] @@ -483,7 +481,9 @@ Route::group(['middleware' => 'web'], function () { )->name('password.email')->middleware('throttle:forgotten_password'); - + // Socialite Google login + Route::get('google', 'App\Http\Controllers\GoogleAuthController@redirectToGoogle')->name('google.redirect'); + Route::get('google/callback', 'App\Http\Controllers\GoogleAuthController@handleGoogleCallback')->name('google.callback'); Route::get( From 72d1c08fbc42bf4de1da7365d4ebf8d30c988d0e Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:21:17 -0700 Subject: [PATCH 02/15] Added migration Signed-off-by: snipe --- ..._10_001836_add_google_auth_to_settings.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 database/migrations/2023_05_10_001836_add_google_auth_to_settings.php diff --git a/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php b/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php new file mode 100644 index 0000000000..5a2bd6a9fa --- /dev/null +++ b/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php @@ -0,0 +1,39 @@ +boolean('google_login')->nullable()->default(0); + $table->string('google_client_id')->nullable()->default(null); + $table->string('google_client_secret')->nullable()->default(null); + $table->string('google_redirect')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('google_login'); + $table->dropColumn('google_client_id'); + $table->dropColumn('google_client_secret'); + $table->dropColumn('google_redirect'); + + }); + } +} From bc9b47c46dcf2906a7690781dabe27038cf60d69 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:27:47 -0700 Subject: [PATCH 03/15] Removed env dependency, switched to DB Signed-off-by: snipe --- .env.example | 9 --------- config/app.php | 9 --------- config/services.php | 3 --- resources/views/auth/login.blade.php | 5 ++++- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/.env.example b/.env.example index 08baf822f5..fbf5c4cfff 100644 --- a/.env.example +++ b/.env.example @@ -175,15 +175,6 @@ REQUIRE_SAML=false API_THROTTLE_PER_MINUTE=120 CSV_ESCAPE_FORMULAS=true - -# -------------------------------------------- -# OPTIONAL: GOOGLE LOGIN -# -------------------------------------------- -ENABLE_GOOGLE_LOGIN=false -GOOGLE_CLIENT_ID=null -GOOGLE_CLIENT_SECRET=null -GOOGLE_REDIRECT_URL=null - # -------------------------------------------- # OPTIONAL: HASHING # -------------------------------------------- diff --git a/config/app.php b/config/app.php index 2913bdc273..2559b8012c 100755 --- a/config/app.php +++ b/config/app.php @@ -218,15 +218,6 @@ return [ 'require_saml' => env('REQUIRE_SAML', false), - /* - |-------------------------------------------------------------------------- - | Enable Google Login - |-------------------------------------------------------------------------- - */ - - 'google_login' => env('ENABLE_GOOGLE_LOGIN', false), - - /* |-------------------------------------------------------------------------- | Demo Mode Lockdown diff --git a/config/services.php b/config/services.php index a0f25664f6..de8c4ed71a 100644 --- a/config/services.php +++ b/config/services.php @@ -51,9 +51,6 @@ return [ 'google' => [ 'maps_api_key' => env('GOOGLE_MAPS_API'), - 'client_id' => env('GOOGLE_CLIENT_ID'), - 'client_secret' => env('GOOGLE_CLIENT_SECRET'), - 'redirect' => env('GOOGLE_REDIRECT_URL'), ], ]; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 730afae833..4b7a1762e7 100755 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -78,8 +78,11 @@ @endif - @if ((config('app.google_login')) && (config('services.google.client_id')) && (config('services.google.client_secret')) && (config('services.google.redirect'))) + @if (($snipeSettings->google_login=='1') && ($snipeSettings->google_client_id!='') && ($snipeSettings->google_client_secret!='') && ($snipeSettings->google_redirect!=''))) +
+ Or +
{{ trans('auth/general.google_login') }} From 054a2ab9d401f8efd3e111237a34b6b1671a644f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:34:31 -0700 Subject: [PATCH 04/15] Add validation and fillable fields Signed-off-by: snipe --- app/Models/Setting.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 61be790e00..775ada58fd 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -76,6 +76,7 @@ class Setting extends Model 'audit_interval' => 'numeric|nullable', 'custom_forgot_pass_url' => 'url|nullable', 'privacy_policy_link' => 'nullable|url', + 'google_redirect' => 'nullable|url', ]; protected $fillable = [ @@ -86,6 +87,10 @@ class Setting extends Model 'webhook_endpoint', 'webhook_channel', 'webhook_botname', + 'google_login', + 'google_client_id', + 'google_client_secret', + 'google_redirect', ]; /** From b183e53c4593c73139728dabd6ebac77fca0786f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:34:48 -0700 Subject: [PATCH 05/15] Added settings routes for google auth Signed-off-by: snipe --- routes/web.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routes/web.php b/routes/web.php index f809f5a3e3..49998f43fc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -192,6 +192,9 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser Route::get('oauth', [SettingsController::class, 'api'])->name('settings.oauth.index'); + Route::get('google', [SettingsController::class, 'getGoogleLoginSettings'])->name('settings.google.index'); + Route::post('google', [SettingsController::class, 'postGoogleLoginSettings'])->name('settings.google.save'); + Route::get('purge', [SettingsController::class, 'getPurge'])->name('settings.purge.index'); Route::post('purge', [SettingsController::class, 'postPurge'])->name('settings.purge.save'); From b7e8ce3064b420956dfe354574abf6e4d2407778 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:54:14 -0700 Subject: [PATCH 06/15] Changed redirect Signed-off-by: snipe --- app/Http/Controllers/GoogleAuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/GoogleAuthController.php b/app/Http/Controllers/GoogleAuthController.php index b24a3a5b25..fea45f5b61 100644 --- a/app/Http/Controllers/GoogleAuthController.php +++ b/app/Http/Controllers/GoogleAuthController.php @@ -42,7 +42,7 @@ class GoogleAuthController extends Controller ]); Auth::login($user, true); - return redirect()->route('setup.done'); + return redirect()->route('home'); } return redirect()->route('login') From aefd330e4eb2c0fed71227af0e50fc0e0b978471 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:54:28 -0700 Subject: [PATCH 07/15] Added methods for google settings Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index c626203cfc..7a09dd41a8 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1039,6 +1039,46 @@ class SettingsController extends Controller return $pdf_branding; } + + /** + * Show Google login settings form + * + * @author [A. Gianotto] [] + * @since [v6.1.1] + * @return View + */ + public function getGoogleLoginSettings() + { + $setting = Setting::getSettings(); + return view('settings.google', compact('setting')); + } + + /** + * ShSaveow Google login settings form + * + * @author [A. Gianotto] [] + * @since [v6.1.1] + * @return View + */ + public function postGoogleLoginSettings(Request $request) + { + if (!$setting = Setting::getSettings()) { + return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); + } + + $setting->google_login = $request->input('google_login', 0); + $setting->google_client_id = $request->input('google_client_id'); + $setting->google_client_secret = $request->input('google_client_secret'); + + if ($setting->save()) { + return redirect()->route('settings.index') + ->with('success', trans('admin/settings/message.update.success')); + } + + return redirect()->back()->withInput()->withErrors($setting->getErrors()); + } + + /** * Show the listing of backups. * From 3fb51880375a54d1b6baacece70baff584810da2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:54:46 -0700 Subject: [PATCH 08/15] Removed redirect option Signed-off-by: snipe --- app/Models/Setting.php | 1 - .../2023_05_10_001836_add_google_auth_to_settings.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 775ada58fd..bc6fb75fb4 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -90,7 +90,6 @@ class Setting extends Model 'google_login', 'google_client_id', 'google_client_secret', - 'google_redirect', ]; /** diff --git a/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php b/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php index 5a2bd6a9fa..7f15e0d6e1 100644 --- a/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php +++ b/database/migrations/2023_05_10_001836_add_google_auth_to_settings.php @@ -17,7 +17,6 @@ class AddGoogleAuthToSettings extends Migration $table->boolean('google_login')->nullable()->default(0); $table->string('google_client_id')->nullable()->default(null); $table->string('google_client_secret')->nullable()->default(null); - $table->string('google_redirect')->nullable()->default(null); }); } @@ -32,7 +31,6 @@ class AddGoogleAuthToSettings extends Migration $table->dropColumn('google_login'); $table->dropColumn('google_client_id'); $table->dropColumn('google_client_secret'); - $table->dropColumn('google_redirect'); }); } From 6ab214d3a6a171295847f76318ea26393cc62d32 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:55:04 -0700 Subject: [PATCH 09/15] Added google option to settings index Signed-off-by: snipe --- resources/views/settings/index.blade.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index 678233c933..4936435a23 100755 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -235,6 +235,21 @@
+ +
From f57e39191d134a49403384f8e57b4b91bf970d72 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:55:16 -0700 Subject: [PATCH 10/15] Added google settings blade Signed-off-by: snipe --- resources/views/settings/google.blade.php | 100 ++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 resources/views/settings/google.blade.php diff --git a/resources/views/settings/google.blade.php b/resources/views/settings/google.blade.php new file mode 100644 index 0000000000..ccd5a10788 --- /dev/null +++ b/resources/views/settings/google.blade.php @@ -0,0 +1,100 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') + Google + @parent +@stop + +@section('header_right') + {{ trans('general.back') }} +@stop + + +{{-- Page content --}} +@section('content') + + + + {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form' ]) }} + + {{csrf_field()}} + +
+
+ + +
+
+

+ Google +

+
+
+ + +
+ + +
+
+ {{ Form::label('google_login', 'Google Login') }} +
+
+ +
+
+ + + +
+
+ {{ Form::label('google_client_id', 'Client ID') }} +
+
+ {{ Form::text('google_client_id', Request::old('google_client_id', $setting->google_client_id), ['class' => 'form-control','placeholder' => trans('general.example') .'000000000000-XXXXXXXXXXX.apps.googleusercontent.com', $setting->demoMode]) }} + {!! $errors->first('google_client_id', '') !!} + @if (config('app.lock_passwords')===true) +

{{ trans('general.feature_disabled') }}

+ @endif +
+
+ + +
+
+ {{ Form::label('google_client_secret', 'Client Secret') }} +
+
+ {{ Form::text('google_client_secret', Request::old('google_client_secret', $setting->google_client_secret), ['class' => 'form-control','placeholder' => trans('general.example') .'XXXXXXXXXXXX', $setting->demoMode]) }} + {!! $errors->first('google_client_secret', '') !!} + @if (config('app.lock_passwords')===true) +

{{ trans('general.feature_disabled') }}

+ @endif +
+
+ +
+ + +
+ +
+
+
+ + {{Form::close()}} + +@stop From 63bf93b7864b292e7a7a511d90de1f34e12e05cf Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 00:56:04 -0700 Subject: [PATCH 11/15] Pulled redirect from settings Signed-off-by: snipe --- app/Models/Setting.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index bc6fb75fb4..807f6a962f 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -76,7 +76,6 @@ class Setting extends Model 'audit_interval' => 'numeric|nullable', 'custom_forgot_pass_url' => 'url|nullable', 'privacy_policy_link' => 'nullable|url', - 'google_redirect' => 'nullable|url', ]; protected $fillable = [ From 4da40792ea3b8048e10406e64fe1f347ae4315f7 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 01:08:28 -0700 Subject: [PATCH 12/15] Use google logo Signed-off-by: snipe --- resources/views/settings/index.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index 4936435a23..83642da669 100755 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -240,12 +240,12 @@
- +

Google Auth
-

Blah

+

Set up Google Login

From 37bc47290c8d20e8316f3be7443d95785a088331 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 01:12:55 -0700 Subject: [PATCH 13/15] Disabled fields in demo mode Signed-off-by: snipe --- resources/views/settings/google.blade.php | 31 +++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/resources/views/settings/google.blade.php b/resources/views/settings/google.blade.php index ccd5a10788..aaae6aa619 100644 --- a/resources/views/settings/google.blade.php +++ b/resources/views/settings/google.blade.php @@ -37,13 +37,13 @@
-
+
{{ Form::label('google_login', 'Google Login') }}
-
@@ -52,11 +52,11 @@
-
+
{{ Form::label('google_client_id', 'Client ID') }}
-
- {{ Form::text('google_client_id', Request::old('google_client_id', $setting->google_client_id), ['class' => 'form-control','placeholder' => trans('general.example') .'000000000000-XXXXXXXXXXX.apps.googleusercontent.com', $setting->demoMode]) }} +
+ {{ Form::text('google_client_id', old('google_client_id', $setting->google_client_id), ['class' => 'form-control','placeholder' => trans('general.example') .'000000000000-XXXXXXXXXXX.apps.googleusercontent.com', (config('app.lock_passwords')===true) ? 'disabled': '']) }} {!! $errors->first('google_client_id', '') !!} @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@@ -66,11 +66,11 @@
-
+
{{ Form::label('google_client_secret', 'Client Secret') }}
-
- {{ Form::text('google_client_secret', Request::old('google_client_secret', $setting->google_client_secret), ['class' => 'form-control','placeholder' => trans('general.example') .'XXXXXXXXXXXX', $setting->demoMode]) }} +
+ {{ Form::text('google_client_secret', old('google_client_secret', $setting->google_client_secret), ['class' => 'form-control','placeholder' => trans('general.example') .'XXXXXXXXXXXX', (config('app.lock_passwords')===true) ? 'disabled': '']) }} {!! $errors->first('google_client_secret', '') !!} @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@@ -78,6 +78,17 @@
+ +
+
+ Redirect URL +
+
+

{{ config('app.url') }}/google/callback

+

This should be entered as your calback URL in your Google OAuth app settings in your Google admin console.

+
+
+
@@ -87,7 +98,7 @@ {{ trans('button.cancel') }}
- +
From 1ef4ea638152851a9c8eab5a98d26ab0b63924df Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 01:14:31 -0700 Subject: [PATCH 14/15] Very ugly login shim just to test functionality Signed-off-by: snipe --- resources/views/auth/login.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 4b7a1762e7..9d1f371cf4 100755 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -78,10 +78,10 @@ @endif - @if (($snipeSettings->google_login=='1') && ($snipeSettings->google_client_id!='') && ($snipeSettings->google_client_secret!='') && ($snipeSettings->google_redirect!=''))) + @if (($snipeSettings->google_login=='1') && ($snipeSettings->google_client_id!='') && ($snipeSettings->google_client_secret!=''))
- Or +
Or

From 3612526632769eae65c1f111f838a224a3e289b4 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 10 May 2023 01:14:54 -0700 Subject: [PATCH 15/15] Disallow saving data if app is locked Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 7a09dd41a8..fbb7f4e4ce 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1062,20 +1062,22 @@ class SettingsController extends Controller */ public function postGoogleLoginSettings(Request $request) { - if (!$setting = Setting::getSettings()) { - return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); + if (!config('app.lock_passwords')) { + $setting = Setting::getSettings(); + + $setting->google_login = $request->input('google_login', 0); + $setting->google_client_id = $request->input('google_client_id'); + $setting->google_client_secret = $request->input('google_client_secret'); + + if ($setting->save()) { + return redirect()->route('settings.index') + ->with('success', trans('admin/settings/message.update.success')); + } + + return redirect()->back()->withInput()->withErrors($setting->getErrors()); } - $setting->google_login = $request->input('google_login', 0); - $setting->google_client_id = $request->input('google_client_id'); - $setting->google_client_secret = $request->input('google_client_secret'); - - if ($setting->save()) { - return redirect()->route('settings.index') - ->with('success', trans('admin/settings/message.update.success')); - } - - return redirect()->back()->withInput()->withErrors($setting->getErrors()); + return redirect()->back()->with('error', trans('general.feature_disabled')); }