Skip to content

Commit b656bc1

Browse files
committed
rename file - adjust things
1 parent 3a5c862 commit b656bc1

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

src/Events/TokenAuthenticated.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Laravel\Sanctum\Events;
4+
5+
class TokenAuthenticated
6+
{
7+
/**
8+
* The personal access token that was authenticated.
9+
*
10+
* @var \Laravel\Sanctum\PersonalAccessToken
11+
*/
12+
public $token;
13+
14+
/**
15+
* Create a new event instance.
16+
*
17+
* @param \Laravel\Sanctum\PersonalAccessToken $token
18+
* @return void
19+
*/
20+
public function __construct($token)
21+
{
22+
$this->token = $token;
23+
}
24+
}

src/Events/TokenValidated.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Guard.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Contracts\Auth\Factory as AuthFactory;
66
use Illuminate\Http\Request;
77
use Illuminate\Support\Arr;
8-
use Laravel\Sanctum\Events\TokenValidated;
8+
use Laravel\Sanctum\Events\TokenAuthenticated;
99

1010
class Guard
1111
{
@@ -71,7 +71,11 @@ public function __invoke(Request $request)
7171
return;
7272
}
7373

74-
event(new TokenValidated($accessToken->tokenable));
74+
$tokenable = $accessToken->tokenable->withAccessToken(
75+
$accessToken
76+
);
77+
78+
event(new TokenAuthenticated($accessToken));
7579

7680
if (method_exists($accessToken->getConnection(), 'hasModifiedRecords') &&
7781
method_exists($accessToken->getConnection(), 'setRecordModificationState')) {
@@ -84,9 +88,7 @@ public function __invoke(Request $request)
8488
$accessToken->forceFill(['last_used_at' => now()])->save();
8589
}
8690

87-
return $accessToken->tokenable->withAccessToken(
88-
$accessToken
89-
);
91+
return $tokenable;
9092
}
9193
}
9294

tests/GuardTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Illuminate\Support\Facades\Event;
1111
use Illuminate\Support\Str;
1212
use Laravel\Sanctum\Contracts\HasApiTokens as HasApiTokensContract;
13-
use Laravel\Sanctum\Events\TokenValidated;
13+
use Laravel\Sanctum\Events\TokenAuthenticated;
1414
use Laravel\Sanctum\Guard;
1515
use Laravel\Sanctum\HasApiTokens;
1616
use Laravel\Sanctum\PersonalAccessToken;
@@ -177,7 +177,7 @@ public function test_authentication_with_token_fails_if_user_provider_is_invalid
177177
$requestGuard = $factory->guard('sanctum');
178178

179179
Event::fake([
180-
TokenValidated::class,
180+
TokenAuthenticated::class,
181181
]);
182182

183183
$request = Request::create('/', 'GET');
@@ -201,7 +201,7 @@ public function test_authentication_with_token_fails_if_user_provider_is_invalid
201201

202202
$this->assertNull($returnedUser);
203203
$this->assertInstanceOf(EloquentUserProvider::class, $requestGuard->getProvider());
204-
Event::assertNotDispatched(TokenValidated::class);
204+
Event::assertNotDispatched(TokenAuthenticated::class);
205205
}
206206

207207
public function test_authentication_is_successful_with_token_if_user_provider_is_valid()
@@ -216,7 +216,7 @@ public function test_authentication_is_successful_with_token_if_user_provider_is
216216
$requestGuard = $factory->guard('sanctum');
217217

218218
Event::fake([
219-
TokenValidated::class,
219+
TokenAuthenticated::class,
220220
]);
221221

222222
$request = Request::create('/', 'GET');
@@ -240,7 +240,7 @@ public function test_authentication_is_successful_with_token_if_user_provider_is
240240

241241
$this->assertEquals($user->id, $returnedUser->id);
242242
$this->assertInstanceOf(EloquentUserProvider::class, $requestGuard->getProvider());
243-
Event::assertDispatched(TokenValidated::class);
243+
Event::assertDispatched(TokenAuthenticated::class);
244244
}
245245

246246
public function test_authentication_fails_if_callback_returns_false()

0 commit comments

Comments
 (0)