Ensure tokens are found in the database using the expected logic

This commit is contained in:
DaneEveritt 2022-05-22 16:05:58 -04:00
parent e9c633fd03
commit f7fc67344e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 39 additions and 25 deletions

View file

@ -195,9 +195,13 @@ class ApiKey extends Model
public static function findToken($token)
{
$id = Str::substr($token, 0, self::IDENTIFIER_LENGTH);
$token = Str::substr($token, strlen($id));
return static::where('identifier', $id)->where('token', encrypt($token))->first();
$model = static::where('identifier', $id)->first();
if (!is_null($model) && decrypt($model->token) === Str::substr($token, strlen($id))) {
return $model;
}
return null;
}
/**