From 67c336169aa7e40178b1288086c4396816c21486 Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Wed, 27 Apr 2022 11:25:51 +0900 Subject: [PATCH 1/6] DP-509: Fixup redirect response --- src/Components/RestHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/RestHandler.php b/src/Components/RestHandler.php index de37aeaf..9ab95908 100644 --- a/src/Components/RestHandler.php +++ b/src/Components/RestHandler.php @@ -16,7 +16,7 @@ use DreamFactory\Core\Exceptions\NotFoundException; use DreamFactory\Core\Utility\ResourcesWrapper; use DreamFactory\Core\Utility\ResponseFactory; -use Symfony\Component\HttpFoundation\RedirectResponse; +use Illuminate\Http\RedirectResponse; use Symfony\Component\HttpFoundation\StreamedResponse; /** From e22b2bc6e47edf122152764680510f0ca017bf6e Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Tue, 24 May 2022 11:05:11 +0900 Subject: [PATCH 2/6] DP-516 Remove confirmation code from json response --- src/Models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/User.php b/src/Models/User.php index c0b86af6..701706b8 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -110,7 +110,7 @@ class User extends BaseSystemModel implements AuthenticatableContract, CanResetP * * @var array */ - protected $hidden = ['is_sys_admin', 'password', 'remember_token', 'security_answer']; + protected $hidden = ['is_sys_admin', 'password', 'remember_token', 'security_answer', 'confirm_code']; /** * Field type casting From 7af2310d33d3d56a0d09f6b0f797a4307cda569d Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Wed, 6 Apr 2022 18:20:29 +0900 Subject: [PATCH 3/6] DP-499 Migration and Authentication for Integrate SSO --- ...add_integrateio_id_field_to_user_table.php | 41 +++++++++++++++++++ src/Utility/Session.php | 19 +++++++++ 2 files changed, 60 insertions(+) create mode 100644 database/migrations/2022_04_06_063114_add_integrateio_id_field_to_user_table.php diff --git a/database/migrations/2022_04_06_063114_add_integrateio_id_field_to_user_table.php b/database/migrations/2022_04_06_063114_add_integrateio_id_field_to_user_table.php new file mode 100644 index 00000000..e37b5a34 --- /dev/null +++ b/database/migrations/2022_04_06_063114_add_integrateio_id_field_to_user_table.php @@ -0,0 +1,41 @@ +integer('integrateio_id')->after('id')->nullable(); + } + ); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + if (Schema::hasColumn('user', 'integrateio_id')) { + Schema::table( + 'user', + function (Blueprint $t){ + $t->dropColumn('integrateio_id'); + } + ); + } + } +} diff --git a/src/Utility/Session.php b/src/Utility/Session.php index fc865b20..e7d40930 100644 --- a/src/Utility/Session.php +++ b/src/Utility/Session.php @@ -668,6 +668,25 @@ public static function replaceLookups(&$subject, $use_private = false) */ public static function authenticate(array $credentials, $remember = false, $login = true, $appId = null) { + + if (isset($credentials['integrateio_id'])) { + $userid = User::where('integrateio_id', $credentials['integrateio_id']) -> first() ->id; + $user = \Auth::loginUsingId($userid); + static::checkRole($user->id); + if ($login) { + /** @noinspection PhpUndefinedFieldInspection */ + $user->last_login_date = Carbon::now()->toDateTimeString(); + /** @noinspection PhpUndefinedFieldInspection */ + $user->confirm_code = 'y'; + /** @noinspection PhpUndefinedMethodInspection */ + $user->save(); + /** @noinspection PhpParamsInspection */ + Session::setUserInfoWithJWT($user, $remember, $appId); + } + + return true; + } + if (\Auth::attempt($credentials)) { $user = \Auth::getLastAttempted(); /** @noinspection PhpUndefinedFieldInspection */ From 8b06a16fe6b2f867fd0d69f29a188e4e98edf9d6 Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Tue, 26 Apr 2022 12:47:07 +0900 Subject: [PATCH 4/6] DP-499 Change Response class to Illuminate --- src/Http/Controllers/RestController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Http/Controllers/RestController.php b/src/Http/Controllers/RestController.php index 55b8cdb0..d7c70cdf 100644 --- a/src/Http/Controllers/RestController.php +++ b/src/Http/Controllers/RestController.php @@ -9,8 +9,7 @@ use DreamFactory\Core\Utility\Session; use Log; use ServiceManager; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; +use Illuminate\Http\RedirectResponse; use Symfony\Component\HttpFoundation\StreamedResponse; /** From 98766c6d3173ec828cea0ac3acbc9d1c9d8dcad7 Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Thu, 9 Jun 2022 14:58:40 +0900 Subject: [PATCH 5/6] DP-499 add integrate_io id as fillable --- src/Models/User.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Models/User.php b/src/Models/User.php index 701706b8..6f155ac6 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -84,7 +84,8 @@ class User extends BaseSystemModel implements AuthenticatableContract, CanResetP 'oauth_provider', 'last_login_date', 'default_app_id', - 'saml' + 'saml', + 'integrateio_id' ]; /** From f000f6029e6e2412af75e24936128fcd83c63a0b Mon Sep 17 00:00:00 2001 From: Tomo Norman Date: Mon, 4 Jul 2022 16:04:22 +0900 Subject: [PATCH 6/6] DP-499 Refactor authentication for Integrate user --- src/Utility/Session.php | 49 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Utility/Session.php b/src/Utility/Session.php index e7d40930..8443ab33 100644 --- a/src/Utility/Session.php +++ b/src/Utility/Session.php @@ -670,36 +670,20 @@ public static function authenticate(array $credentials, $remember = false, $logi { if (isset($credentials['integrateio_id'])) { - $userid = User::where('integrateio_id', $credentials['integrateio_id']) -> first() ->id; - $user = \Auth::loginUsingId($userid); + $user = static::loginIntegrateUser($credentials); + /** @noinspection PhpUndefinedFieldInspection */ static::checkRole($user->id); if ($login) { - /** @noinspection PhpUndefinedFieldInspection */ - $user->last_login_date = Carbon::now()->toDateTimeString(); - /** @noinspection PhpUndefinedFieldInspection */ - $user->confirm_code = 'y'; - /** @noinspection PhpUndefinedMethodInspection */ - $user->save(); - /** @noinspection PhpParamsInspection */ - Session::setUserInfoWithJWT($user, $remember, $appId); + static::confirmUserLogin($user, $remember, $appId); } return true; - } - - if (\Auth::attempt($credentials)) { + } else if (\Auth::attempt($credentials)) { $user = \Auth::getLastAttempted(); /** @noinspection PhpUndefinedFieldInspection */ static::checkRole($user->id); if ($login) { - /** @noinspection PhpUndefinedFieldInspection */ - $user->last_login_date = Carbon::now()->toDateTimeString(); - /** @noinspection PhpUndefinedFieldInspection */ - $user->confirm_code = 'y'; - /** @noinspection PhpUndefinedMethodInspection */ - $user->save(); - /** @noinspection PhpParamsInspection */ - Session::setUserInfoWithJWT($user, $remember, $appId); + static::confirmUserLogin($user, $remember, $appId); } return true; @@ -708,6 +692,29 @@ public static function authenticate(array $credentials, $remember = false, $logi } } + /** + * @param array $credentials + * @return User + * @throws \Exception + */ + protected static function loginIntegrateUser(array $credentials) { + $userid = User::where('integrateio_id', $credentials['integrateio_id']) -> first() ->id; + $user = \Auth::loginUsingId($userid); + + return $user; + } + + protected static function confirmUserLogin($user, $remember, $appId) { + /** @noinspection PhpUndefinedFieldInspection */ + $user->last_login_date = Carbon::now()->toDateTimeString(); + /** @noinspection PhpUndefinedFieldInspection */ + $user->confirm_code = 'y'; + /** @noinspection PhpUndefinedMethodInspection */ + $user->save(); + /** @noinspection PhpParamsInspection */ + Session::setUserInfoWithJWT($user, $remember, $appId); + } + /** * @param $userId *