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 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
62 changes: 48 additions & 14 deletions src/Auth0/Login/Auth0Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,58 @@

namespace Auth0\Login;

use Config;
use Auth0\SDK\API\Authentication;
use Auth0\SDK\API\Helpers\State\SessionStateHandler;
use Auth0\SDK\Auth0;
use Auth0\SDK\JWTVerifier;
use Auth0\SDK\Helpers\Cache\CacheHandler;
use Auth0\SDK\JWTVerifier;
use Auth0\SDK\Store\StoreInterface;
use Config;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\RedirectResponse;

/**
* Service that provides access to the Auth0 SDK.
*/
class Auth0Service
{
private $auth0Config;
/**
* @var Auth0
*/
private $auth0;
private $authApi;

private $apiuser;
private $_onLoginCb = null;
private $rememberUser = false;

public function __construct() {
$this->auth0Config = config('laravel-auth0');

$this->auth0Config['store'] = new LaravelSessionStore();

$this->authApi = new Authentication($this->auth0Config['domain'], $this->auth0Config['client_id']);
/**
* Auth0Service constructor.
*
* @param array $auth0Config
* @param StoreInterface $sessionStorage
*
* @throws \Auth0\SDK\Exception\CoreException
*/
public function __construct(
array $auth0Config = null,
StoreInterface $sessionStorage = null,
SessionStateHandler $sessionStateHandler = null
)
{
// Backwards compatible fallbacks
if (!$auth0Config instanceof Repository && !is_array($auth0Config)) {
$auth0Config = config('laravel-auth0');
}
if (!$sessionStorage instanceof StoreInterface) {
$sessionStorage = new LaravelSessionStore();
}
if (!$sessionStateHandler instanceof SessionStateHandler) {
$sessionStateHandler = new SessionStateHandler($sessionStorage);
}

$this->auth0 = new Auth0($this->auth0Config);
$auth0Config['store'] = $sessionStorage;
$auth0Config['state_handler'] = $sessionStateHandler;
$this->auth0 = new Auth0($auth0Config);
}

/**
Expand All @@ -54,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 Expand Up @@ -139,7 +173,7 @@ public function decodeJWT($encUser)
$secret_base64_encoded = config('laravel-auth0.secret_base64_encoded');

if (is_null($secret_base64_encoded)) {
$secret_base64_encoded = true;
$secret_base64_encoded = true;
}

$verifier = new JWTVerifier([
Expand Down
1 change: 1 addition & 0 deletions src/Auth0/Login/LaravelSessionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LaravelSessionStore implements StoreInterface
public function set($key, $value)
{
$key_name = $this->getSessionKeyName($key);

Session::put($key_name, $value);
}

Expand Down
25 changes: 20 additions & 5 deletions src/Auth0/Login/LoginServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Auth0\Login;

use Illuminate\Support\ServiceProvider;
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Helpers\InformationHeaders;
use Auth0\SDK\API\Helpers\State\SessionStateHandler;
use Auth0\SDK\Store\StoreInterface;
use Illuminate\Support\ServiceProvider;

class LoginServiceProvider extends ServiceProvider {
class LoginServiceProvider extends ServiceProvider
{

const SDK_VERSION = "4.0.4";

Expand Down Expand Up @@ -49,12 +52,24 @@ public function boot()
*/
public function register()
{
$this->app->bind(StoreInterface::class, function () {
return new LaravelSessionStore();
});

$this->app->bind(SessionStateHandler::class, function ($app) {
return new SessionStateHandler($app->make(LaravelSessionStore::class));
});

// Bind the auth0 name to a singleton instance of the Auth0 Service
$this->app->singleton(Auth0Service::class, function () {
return new Auth0Service();
$this->app->singleton(Auth0Service::class, function ($app) {
return new Auth0Service(
$app->make('config')->get('laravel-auth0'),
$app->make(StoreInterface::class),
$app->make(SessionStateHandler::class)
);
});
$this->app->singleton('auth0', function () {
return $this->app->make(Auth0Service::class);
return $this->app->make(Auth0Service::class);
});

// When Laravel logs out, logout the auth0 SDK trough the service
Expand Down