Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DP-499 Integrateio sso #102

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddIntegrateioIdFieldToUserTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasColumn('user', 'integrateio_id')) {
Schema::table(
'user',
function (Blueprint $t){
$t->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');
}
);
}
}
}
2 changes: 1 addition & 1 deletion src/Components/RestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Controllers/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class User extends BaseSystemModel implements AuthenticatableContract, CanResetP
'oauth_provider',
'last_login_date',
'default_app_id',
'saml'
'saml',
'integrateio_id'
];

/**
Expand All @@ -110,7 +111,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
Expand Down
44 changes: 35 additions & 9 deletions src/Utility/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,19 +668,22 @@ public static function replaceLookups(&$subject, $use_private = false)
*/
public static function authenticate(array $credentials, $remember = false, $login = true, $appId = null)
{
if (\Auth::attempt($credentials)) {

if (isset($credentials['integrateio_id'])) {
$user = static::loginIntegrateUser($credentials);
/** @noinspection PhpUndefinedFieldInspection */
static::checkRole($user->id);
if ($login) {
tomonorman marked this conversation as resolved.
Show resolved Hide resolved
static::confirmUserLogin($user, $remember, $appId);
}

return true;
} 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;
Expand All @@ -689,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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this y? Is it not an issue if it's the same value for all users? I see confirm_code which is usually a security feature, so I am just wondering.
@tomonorman @krishnapriawan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just means the user is "confirmed" (yes, no) rather than an actual "code" so to speak.

/** @noinspection PhpUndefinedMethodInspection */
$user->save();
/** @noinspection PhpParamsInspection */
Session::setUserInfoWithJWT($user, $remember, $appId);
}

/**
* @param $userId
*
Expand Down