Commit 03eca62f authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

get the api authentication actually working

parent 53306e15
......@@ -5,6 +5,7 @@ namespace App\Guards;
use App\User;
use App\Token;
use Illuminate\Http\Request;
use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Guard;
......@@ -18,28 +19,21 @@ class ApiGuard implements Guard {
*
* @var Request
*/
protected $request;
protected Request $request;
/**
* The name of the query string item from the request containing the API token.
*
* @var string
*/
protected $inputKey;
protected string $inputKey;
/**
* The name of the token "column" in persistent storage.
*
* @var string
*/
protected $storageKey;
/**
* Indicates if the API token is hashed in storage.
*
* @var bool
*/
protected $hash = false;
protected string $storageKey;
/**
* Create a new authentication guard.
......@@ -85,9 +79,9 @@ class ApiGuard implements Guard {
/**
* Get the token for the current request.
*
* @return string
* @return string|null
*/
public function getTokenForRequest(): string {
public function getTokenForRequest(): ?string {
$token = $this->request->query($this->inputKey);
if (empty($token)) {
......@@ -141,6 +135,10 @@ class ApiGuard implements Guard {
* @return Authenticatable|null
*/
public function retrieveByToken(string $token): ?Authenticatable {
return User::tokens()->where($this->storageKey, $token)->first();
$token = Token::where($this->storageKey, $token)->first();
if ($token) {
return $token->user()->first();
}
return null;
}
}
......@@ -3,8 +3,16 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Token extends Model
{
//
protected $table = 'user_tokens';
/**
* @return BelongsTo
*/
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
}
......@@ -26,7 +26,6 @@ class CreateUsersTable extends Migration
// hashed
$table->string('doorcode');
$table->timestamp('expires_at')->nullable();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment