Skip to content

Fixed Error "Cannot use object of type MongoDB\BSON\UTCDateTime as array" #1352

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

Merged
merged 2 commits into from
Apr 26, 2018
Merged
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
18 changes: 9 additions & 9 deletions src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
*/
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $token, 'created_at' => new UTCDateTime(time() * 1000)];
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new UTCDateTime(time() * 1000)];
}

/**
* @inheritdoc
*/
protected function tokenExpired($token)
protected function tokenExpired($createdAt)
{
// Convert UTCDateTime to a date string.
if ($token['created_at'] instanceof UTCDateTime) {
$date = $token['created_at']->toDateTime();
if ($createdAt instanceof UTCDateTime) {
$date = $createdAt->toDateTime();
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s');
} elseif (is_array($token['created_at']) && isset($token['created_at']['date'])) {
$date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC'));
$createdAt = $date->format('Y-m-d H:i:s');
} elseif (is_array($createdAt) and isset($createdAt['date'])) {
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s');
$createdAt = $date->format('Y-m-d H:i:s');
}

return parent::tokenExpired($token);
return parent::tokenExpired($createdAt);
}
}
30 changes: 14 additions & 16 deletions src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ class PasswordBrokerManager extends BasePasswordBrokerManager
*/
protected function createTokenRepository(array $config)
{
$laravel = app();

if (version_compare($laravel::VERSION, '5.4', '>=')) {
return new DatabaseTokenRepository(
$this->app['db']->connection(),
$this->app['hash'],
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
} else {
return new DatabaseTokenRepository(
$this->app['db']->connection(),
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
$key = $this->app['config']['app.key'];

if (\Illuminate\Support\Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
}

$connection = isset($config['connection']) ? $config['connection'] : null;

return new DatabaseTokenRepository(
$this->app['db']->connection(),
$this->app['hash'],
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
}
}