Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jan 18, 2024
2 parents 22bf821 + 02ceac4 commit 28458c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Release Notes

## [Unreleased](https://github.com/laravel/sanctum/compare/v3.3.2...3.x)
## [Unreleased](https://github.com/laravel/sanctum/compare/v3.3.3...3.x)

## [v3.3.3](https://github.com/laravel/sanctum/compare/v3.3.2...v3.3.3) - 2023-12-19

* Updated `CsrfCookieController` to use named arguments by [@OussamaMater](https://github.com/OussamaMater) in https://github.com/laravel/sanctum/pull/487
* Extract generate token method by [@mowangjuanzi](https://github.com/mowangjuanzi) in https://github.com/laravel/sanctum/pull/488

## [v3.3.2](https://github.com/laravel/sanctum/compare/v3.3.1...v3.3.2) - 2023-11-03

Expand Down
22 changes: 16 additions & 6 deletions src/HasApiTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ public function tokenCan(string $ability)
*/
public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null)
{
$plainTextToken = sprintf(
'%s%s%s',
config('sanctum.token_prefix', ''),
$tokenEntropy = Str::random(40),
hash('crc32b', $tokenEntropy)
);
$plainTextToken = $this->generateTokenString();

$token = $this->tokens()->create([
'name' => $name,
Expand All @@ -62,6 +57,21 @@ public function createToken(string $name, array $abilities = ['*'], DateTimeInte
return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken);
}

/**
* Generate the token string.
*
* @return string
*/
public function generateTokenString()
{
return sprintf(
'%s%s%s',
config('sanctum.token_prefix', ''),
$tokenEntropy = Str::random(40),
hash('crc32b', $tokenEntropy)
);
}

/**
* Get the access token currently associated with the user.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/CsrfCookieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class CsrfCookieController
public function show(Request $request)
{
if ($request->expectsJson()) {
return new JsonResponse(null, 204);
return new JsonResponse(status: 204);
}

return new Response('', 204);
return new Response(status: 204);
}
}

0 comments on commit 28458c6

Please sign in to comment.