Skip to content

Commit a4e1d6f

Browse files
authored
Merge pull request #21 from givebutter/jhoff/authenticate_event
2 parents 4bcadf5 + a1adba2 commit a4e1d6f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Givebutter\LaravelKeyable\Events;
4+
5+
use Givebutter\LaravelKeyable\Models\ApiKey;
6+
7+
class KeyableAuthenticated
8+
{
9+
public function __construct(public ApiKey $apiKey)
10+
{
11+
}
12+
}

src/Http/Middleware/AuthenticateApiKey.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Givebutter\LaravelKeyable\Models\ApiKey;
7+
use Givebutter\LaravelKeyable\Events\KeyableAuthenticated;
78

89
class AuthenticateApiKey
910
{
@@ -19,7 +20,7 @@ class AuthenticateApiKey
1920
public function handle($request, Closure $next, $guard = null)
2021
{
2122
$forbidenRequestParams = ['apiKey', 'keyable'];
22-
23+
2324
// Check if request has forbidden params
2425
foreach ($forbidenRequestParams as $param) {
2526
if ($request->missing($param)) {
@@ -74,6 +75,8 @@ public function handle($request, Closure $next, $guard = null)
7475
//Update last_used_at
7576
$apiKey->markAsUsed();
7677

78+
event(new KeyableAuthenticated($apiKey));
79+
7780
//Return
7881
return $next($request);
7982
}

0 commit comments

Comments
 (0)