Skip to content

Commit

Permalink
Use Laravel for redirect; update PHP SDK; remove Session::save()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Sep 26, 2019
1 parent 4c0511b commit 2f24656
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.* | ^6.0",
"auth0/auth0-php": "^5.1.0",
"auth0/auth0-php": "^5.6.0",
"illuminate/contracts": "5.* | ^6.0"
},
"autoload": {
Expand Down
13 changes: 11 additions & 2 deletions src/Auth0/Login/Auth0Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Config;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\RedirectResponse;

/**
* Service that provides access to the Auth0 SDK.
Expand Down Expand Up @@ -50,7 +51,6 @@ public function __construct(
$sessionStateHandler = new SessionStateHandler($sessionStorage);
}


$auth0Config['store'] = $sessionStorage;
$auth0Config['state_handler'] = $sessionStateHandler;
$this->auth0 = new Auth0($auth0Config);
Expand Down Expand Up @@ -79,8 +79,17 @@ public function logout()
*/
public function login($connection = null, $state = null, $additional_params = ['scope' => 'openid profile email'], $response_type = 'code')
{
if ($connection && empty( $additional_params['connection'] )) {
$additional_params['connection'] = $connection;
}

if ($state && empty( $additional_params['state'] )) {
$additional_params['state'] = $state;
}

$additional_params['response_type'] = $response_type;
$this->auth0->login($state, $connection, $additional_params);
$auth_url = $this->auth0->getLoginUrl($additional_params);
return new RedirectResponse($auth_url);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Auth0/Login/LaravelSessionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ class LaravelSessionStore implements StoreInterface
public function set($key, $value)
{
$key_name = $this->getSessionKeyName($key);
Session::put($key_name, $value);

// The Auth0 SDK might decide to redirect and exit the PHP execution
// before the Laravel middleware can write the changes.
// thus we have to persist our changes early
Session::save();
Session::put($key_name, $value);
}

/**
Expand Down

0 comments on commit 2f24656

Please sign in to comment.