Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Middleware/EnsureFrontendRequestsAreStateful.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function fromFrontend($request)
$stateful = array_filter(config('sanctum.stateful', []));

return Str::is(Collection::make($stateful)->map(function ($uri) use ($request) {
$uri = $uri === Sanctum::currentRequestHost() ? $request->getHttpHost() : $uri;
$uri = $uri === Sanctum::$currentRequestHostPlaceholder ? $request->getHttpHost() : $uri;

return trim($uri).'/*';
})->all(), $domain);
Expand Down
9 changes: 8 additions & 1 deletion src/Sanctum.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Sanctum
*/
public static $accessTokenAuthenticationCallback;

/**
* A placeholder to instruct Sanctum to include the current request host in the list of stateful domains.
*
* @var string;
*/
public static $currentRequestHostPlaceholder = '__SANCTUM_CURRENT_REQUEST_HOST__';

/**
* Get the current application URL from the "APP_URL" environment variable - with port.
*
Expand All @@ -49,7 +56,7 @@ public static function currentApplicationUrlWithPort()
*/
public static function currentRequestHost()
{
return '__SANCTUM_CURRENT_REQUEST_HOST__';
return ','.static::$currentRequestHostPlaceholder;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/EnsureFrontendRequestsAreStatefulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function test_same_domain_stateful()
config(['sanctum.stateful' => []]);
$this->assertFalse(EnsureFrontendRequestsAreStateful::fromFrontend($request));

config(['sanctum.stateful' => [Sanctum::currentRequestHost()]]);
config(['sanctum.stateful' => [Sanctum::$currentRequestHostPlaceholder]]);
$this->assertTrue(EnsureFrontendRequestsAreStateful::fromFrontend($request));
}

Expand Down