Skip to content

Commit

Permalink
add doctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
LAHAXE Arnaud authored and LAHAXE Arnaud committed May 18, 2015
1 parent 7696a5c commit 23888ee
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

/**
* Class CreateU2fKeyTable
*
*
*
* @author LAHAXE Arnaud
*/
class CreateU2fKeyTable extends Migration
{

Expand Down Expand Up @@ -37,7 +44,5 @@ public function up()
public function down()
{
Schema::drop('u2f_key');

}

}
56 changes: 54 additions & 2 deletions src/LaravelU2f.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,52 @@
use App\User;
use Lahaxearnaud\U2f\Models\U2fKey;

/**
* Class LaravelU2f
*
*
*
* @package Lahaxearnaud\U2f
* @author LAHAXE Arnaud
*/
class LaravelU2f {

/**
* @var \u2flib_server\U2F
*/
protected $u2f;

/**
*
*/
public function __construct()
{
$scheme = \Request::isSecure() ? "https://" : "http://";
$this->u2f = new \u2flib_server\U2F($scheme . \Request::getHttpHost());
}

/**
* @author LAHAXE Arnaud
*
* @param \App\User $user
*
* @return mixed
*/
public function getRegisterData(User $user)
{

return $this->u2f->getRegisterData(U2fKey::where('user_id', $user->id)->get()->all());
}

/**
* @author LAHAXE Arnaud
*
* @param \App\User $user
* @param $registerData
* @param $keyData
*
* @return mixed
*/
public function doRegister(User $user, $registerData, $keyData)
{
$reg = $this->u2f->doRegister($registerData, $keyData);
Expand All @@ -27,12 +57,28 @@ public function doRegister(User $user, $registerData, $keyData)
return U2fKey::create((array) $reg);
}

/**
* @author LAHAXE Arnaud
*
* @param \App\User $user
*
* @return mixed
*/
public function getAuthenticateData(User $user)
{

return $this->u2f->getAuthenticateData(U2fKey::where('user_id', $user->id)->get()->all());
}

/**
* @author LAHAXE Arnaud
*
* @param \App\User $user
* @param $authData
* @param $keyData
*
* @return bool
*/
public function doAuthenticate(User $user, $authData, $keyData)
{

Expand All @@ -56,13 +102,19 @@ public function doAuthenticate(User $user, $authData, $keyData)
$U2fKey->save();


\Session::set('otp', true);
\Session::set('u2f', true);

return $U2fKey;
}

/**
* @author LAHAXE Arnaud
*
*
* @return mixed
*/
public function check()
{
return \Session::get('otp', false);
return \Session::get('u2f', false);
}
}
2 changes: 1 addition & 1 deletion src/Models/U2fKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Class OtpKey
*
* @author LAHAXE Arnaud <lahaxe.arnaud@gmail.com>
* @author LAHAXE Arnaud
* @package Lahaxearnaud\U2f\Models
*/
class U2fKey extends Model
Expand Down
15 changes: 8 additions & 7 deletions src/http/Controllers/AssetController.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php namespace Lahaxearnaud\U2f\Http\Controllers;

/**
* Created by PhpStorm.
* Author LAHAXE Arnaud <lahaxe.arnaud@gmail.com>
* Date: 18/05/15
* Time: 07:32
*/

use Illuminate\Http\Response;

use App\Http\Controllers\Controller;

/**
* Class AssetController
*
*
*
* @package Lahaxearnaud\U2f\Http\Controllers
* @author LAHAXE Arnaud
*/
class AssetController extends Controller{

public function js ()
Expand Down
34 changes: 32 additions & 2 deletions src/http/Controllers/U2fController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ class U2fController extends Controller
*/
protected $u2f;

/**
* @param \Lahaxearnaud\U2f\LaravelU2f $u2f
*/
public function __construct(LaravelU2f $u2f)
{
$this->u2f = $u2f;
}

/**
* @author LAHAXE Arnaud
*
*
* @return mixed
*/
public function registerData()
{
list($req, $sigs) = $this->u2f->getRegisterData(\Auth::user());
\Event::fire('u2f.register.data', [ 'user' => \Auth::user()]);

\Session::set('registerData', $req);

Expand All @@ -29,11 +39,17 @@ public function registerData()

}

/**
* @author LAHAXE Arnaud
*
*
* @return mixed
*/
public function register()
{
try {
$key = $this->u2f->doRegister(\Auth::user(), \Session::get('registerData'), json_decode(\Input::get('register')));
\Event::fire('u2f.register', [ 'u2fKey' => $key ]);
\Event::fire('u2f.register', [ 'u2fKey' => $key, 'user' => \Auth::user()]);

return redirect('/');

Expand All @@ -43,20 +59,34 @@ public function register()
}
}

/**
* @author LAHAXE Arnaud
*
*
* @return mixed
*/
public function authData()
{
$req = $this->u2f->getAuthenticateData(\Auth::user());
\Event::fire('u2f.authentification.data', [ 'user' => \Auth::user()]);

\Session::set('authentificationData', $req);

return view('u2f::authentification')
->with('authentificationData', $req);
}

/**
* @author LAHAXE Arnaud
*
*
* @return mixed
*/
public function auth()
{
try {
$this->u2f->doAuthenticate(\Auth::user(), \Session::get('authentificationData'), json_decode(\Input::get('authentification')));
$key = $this->u2f->doAuthenticate(\Auth::user(), \Session::get('authentificationData'), json_decode(\Input::get('authentification')));
\Event::fire('u2f.authentification', [ 'u2fKey' => $key, 'user' => \Auth::user()]);

return redirect('/');

Expand Down
8 changes: 8 additions & 0 deletions src/http/Middleware/U2f.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
use Illuminate\Http\Response;
use Lahaxearnaud\U2f\LaravelU2f;

/**
* Class U2f
*
*
*
* @package Lahaxearnaud\U2f\Http\Middleware
* @author LAHAXE Arnaud
*/
class U2f
{

Expand Down

0 comments on commit 23888ee

Please sign in to comment.