Skip to content

Commit 3fddd59

Browse files
committed
Allow store and state_handler to be passed in from config
1 parent a008725 commit 3fddd59

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/Auth0/Login/Auth0Service.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Auth0\Login;
44

5+
use Auth0\SDK\API\Helpers\State\StateHandler;
56
use Auth0\SDK\API\Helpers\State\SessionStateHandler;
67
use Auth0\SDK\Auth0;
78
use Auth0\SDK\Helpers\Cache\CacheHandler;
@@ -36,23 +37,26 @@ class Auth0Service
3637
*/
3738
public function __construct(
3839
array $auth0Config = null,
39-
StoreInterface $sessionStorage = null,
40-
SessionStateHandler $sessionStateHandler = null
40+
StoreInterface $store = null,
41+
StateHandler $stateHandler = null
4142
)
4243
{
43-
// Backwards compatible fallbacks
4444
if (!$auth0Config instanceof Repository && !is_array($auth0Config)) {
4545
$auth0Config = config('laravel-auth0');
4646
}
47-
if (!$sessionStorage instanceof StoreInterface) {
48-
$sessionStorage = new LaravelSessionStore();
47+
48+
$store = $auth0Config['store'] ?? $store;
49+
if (false !== $store && !$store instanceof StoreInterface) {
50+
$store = new LaravelSessionStore();
4951
}
50-
if (!$sessionStateHandler instanceof SessionStateHandler) {
51-
$sessionStateHandler = new SessionStateHandler($sessionStorage);
52+
53+
$stateHandler = $auth0Config['state_handler'] ?? $stateHandler;
54+
if (false !== $stateHandler && !$stateHandler instanceof StateHandler) {
55+
$stateHandler = new SessionStateHandler($store);
5256
}
5357

54-
$auth0Config['store'] = $sessionStorage;
55-
$auth0Config['state_handler'] = $sessionStateHandler;
58+
$auth0Config['store'] = $store;
59+
$auth0Config['state_handler'] = $stateHandler;
5660
$this->auth0 = new Auth0($auth0Config);
5761
}
5862

src/Auth0/Login/LoginServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Auth0\SDK\API\Helpers\ApiClient;
66
use Auth0\SDK\API\Helpers\InformationHeaders;
7+
use Auth0\SDK\API\Helpers\State\StateHandler;
78
use Auth0\SDK\API\Helpers\State\SessionStateHandler;
89
use Auth0\SDK\Store\StoreInterface;
910
use Illuminate\Support\ServiceProvider;
@@ -49,7 +50,7 @@ public function register()
4950
return new LaravelSessionStore();
5051
});
5152

52-
$this->app->bind(SessionStateHandler::class, function ($app) {
53+
$this->app->bind(StateHandler::class, function ($app) {
5354
return new SessionStateHandler($app->make(LaravelSessionStore::class));
5455
});
5556

@@ -58,7 +59,7 @@ public function register()
5859
return new Auth0Service(
5960
$app->make('config')->get('laravel-auth0'),
6061
$app->make(StoreInterface::class),
61-
$app->make(SessionStateHandler::class)
62+
$app->make(StateHandler::class)
6263
);
6364
});
6465
$this->app->singleton('auth0', function () {

0 commit comments

Comments
 (0)