Using custom digester

This commit is contained in:
Christophe LATOUR 2017-08-03 11:04:29 +02:00
parent 94e719132b
commit bf5467515d
5 changed files with 52 additions and 27 deletions

View File

@ -3,17 +3,12 @@
namespace App\Providers;
use App\Models\User;
use Antadis\Auth\Wsse\WsseAuthServiceProvider;
use Antadis\Security\Wsse\WsseHeaderGenerator;
use Antadis\Security\Wsse\Dater;
use Antadis\Security\Wsse\Noncer;
use Antadis\Security\Wsse\Digester;
use Antadis\Gateways\Prestashop;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use ApiUser;
class AuthServiceProvider extends ServiceProvider
class AuthServiceProvider extends WsseAuthServiceProvider
{
/**
* Register any application services.
@ -32,16 +27,29 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->app['auth']->viaRequest('api', function ($request) {
//BRICO USER 2553994 (latour@antadis.com)
//BBB USER 952478 (marion@antadis.com)
$user = new ApiUser(952478);
if (\Validate::isLoadedObject($user)) {
return $user;
} else {
return null;
}
return User::findByEmail('latour@antadis.com');
});
if (env('APP_DEBUG') === true) {
$this->app['auth']->viaRequest('api', function ($request) {
//BRICO USER 2553994 (latour@antadis.com)
//BBB USER 952478 (marion@antadis.com)
$user = new ApiUser(952478);
if (\Validate::isLoadedObject($user)) {
return $user;
} else {
return null;
}
});
} else {
parent::boot();
}
}
/**
* Return the digester
*
* @return Antadis\Security\Wsse\Digester
*/
protected function getDigester() {
return new Digester();
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Providers;
use Antadis\Security\Wsse\DigesterInterface;
class Digester implements DigesterInterface {
/**
* @return string
*/
public function generate($nonce, $created, $password) {
return base64_encode(sha1($nonce.$created.$password, false));
}
}

View File

@ -95,14 +95,7 @@ $app->routeMiddleware([
|
*/
//$app->register(Antadis\Gateways\Prestashop\ServiceProvider::class);
if (env('APP_DEBUG') === true) {
//AUTOLOGGED USER
$app->register(App\Providers\AuthServiceProvider::class);
} else {
//REAL APP USER
$app->register(Antadis\Auth\Wsse\WsseAuthServiceProvider::class);
}
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Barryvdh\Cors\ServiceProvider::class);
$app->register(Antadis\API\Front\ApiProvider::class);

View File

@ -6,7 +6,8 @@ return array(
'ApiTag' => 'App\Models\Tag',
'ApiCart' => 'App\Models\Cart',
'ApiCarrier' => 'App\Models\Carrier',
'ApiOrderDetail' => 'App\Models\Order\OrderDetail'
'ApiOrderDetail' => 'App\Models\Order\OrderDetail',
'ApiUser' => 'App\Models\User',
],
'controllers' => [
'ApiBaseController' => 'App\Web\Controllers\Controller',

9
config/wsse.php Normal file
View File

@ -0,0 +1,9 @@
<?php
return array(
/* USER MODEL TO USE */
'userModel' => 'App\\Models\\User',
/* HOW MUCH TIME THE SIGNATURE IS ALIVE. PUT IT TO 0 TO ENABLE ENDLESS SIGNATURES */
'ttl' => 0,
);