Skip to content

Commit

Permalink
Merge pull request #113 from dreamfactorysoftware/develop
Browse files Browse the repository at this point in the history
Add session token expiration time to user public info
  • Loading branch information
Anas committed Mar 28, 2023
2 parents ccf6d3f + 36b561b commit 646c99e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Utility/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
use DreamFactory\Core\Models\Role;
use DreamFactory\Core\Models\User;
use DreamFactory\Core\Models\UserAppRole;
use Illuminate\Support\Facades\Auth;
use ServiceManager;
use Tymon\JWTAuth\Exceptions\TokenBlacklistedException;
use JWTAuth;

class Session
{
Expand Down Expand Up @@ -668,8 +670,8 @@ public static function replaceLookups(&$subject, $use_private = false)
*/
public static function authenticate(array $credentials, $remember = false, $login = true, $appId = null)
{
if (\Auth::attempt($credentials)) {
$user = \Auth::getLastAttempted();
if (Auth::attempt($credentials)) {
$user = Auth::getLastAttempted();
/** @noinspection PhpUndefinedFieldInspection */
static::checkRole($user->id);
if ($login) {
Expand Down Expand Up @@ -910,9 +912,13 @@ public static function getPublicInfo()
'email' => session('user.email'),
'is_sys_admin' => session('user.is_sys_admin'),
'last_login_date' => session('user.last_login_date'),
'host' => gethostname()
'host' => gethostname(),
];

// Get the TTL in minutes and then convert it to seconds
$ttl = JWTAuth::manager()->getPayloadFactory()->getTTL() * 60;
// Convert the TTL to date format
$formattedTTL = Carbon::now()->addSeconds($ttl)->format('Y-m-d H:i:s');
$sessionData['token_expiry_date'] = $formattedTTL;
$role = static::get('role');
if (!empty($role)) {
$sessionData['role'] = array_get($role, 'name');
Expand Down

0 comments on commit 646c99e

Please sign in to comment.