1. Go to this page and download the library: Download darkghosthunter/larapass library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable;
use DarkGhostHunter\Larapass\WebAuthnAuthentication;
class User extends Authenticatable implements WebAuthnAuthenticatable
{
use WebAuthnAuthentication;
// ...
}
use App\Http\Controllers\Auth\WebAuthnRegisterController;
use App\Http\Controllers\Auth\WebAuthnLoginController;
Route::post('webauthn/register/options', [WebAuthnRegisterController::class, 'options'])
->name('webauthn.register.options');
Route::post('webauthn/register', [WebAuthnRegisterController::class, 'register'])
->name('webauthn.register');
Route::post('webauthn/login/options', [WebAuthnLoginController::class, 'options'])
->name('webauthn.login.options');
Route::post('webauthn/login', [WebAuthnLoginController::class, 'login'])
->name('webauthn.login');
public function handle(AttestationSuccessful $event)
{
$event->user->notify(
new DeviceRegisteredNotification($event->credential->getId())
);
}
use App\User;
use Illuminate\Support\Facades\Auth;
use DarkGhostHunter\Larapass\Facades\WebAuthn;
$user = Auth::user();
// Create an attestation for a given user.
return WebAuthn::generateAttestation($user);
use App\User;
use Illuminate\Support\Facades\Auth;
use DarkGhostHunter\Larapass\Facades\WebAuthn;
$user = Auth::user();
// Verify it
$credential = WebAuthn::validateAttestation(
request()->json()->all(), $user
);
// And save it.
if ($credential) {
$user->addCredential($credential);
} else {
return 'Something went wrong with your device!';
}
use App\User;
use DarkGhostHunter\Larapass\Facades\WebAuthn;
// Find the user to assert, if there is any
$user = User::where('email', request()->input('email'))->first();
// Create an assertion for the given user (or a blank one if not found);
return WebAuthn::generateAssertion($user);
use App\User;
use Illuminate\Support\Facades\Auth;
use DarkGhostHunter\Larapass\Facades\WebAuthn;
// Verify the incoming assertion.
$credentials = WebAuthn::validateAssertion(
request()->json()->all()
);
// If is valid, login the user of the credentials.
if ($credentials) {
Auth::login(
User::getFromCredentialId($credentials->getPublicKeyCredentialId())
);
}
return [
'algorithms' => [
\Cose\Algorithm\Signature\ECDSA\ES256::class, // ECDSA with SHA-256
\Cose\Algorithm\Signature\EdDSA\Ed25519::class, // EdDSA
\Cose\Algorithm\Signature\ECDSA\ES384::class, // ECDSA with SHA-384
\Cose\Algorithm\Signature\ECDSA\ES512::class, // ECDSA with SHA-512
\Cose\Algorithm\Signature\RSA\RS256::class, // RSASSA-PKCS1-v1_5 with SHA-256
],
];
return [
'attachment' => null,
];
return [
'conveyance' => null,
];
return [
'login_verify' => 'preferred',
];
return [
'userless' => null,
];
return [
'unique' => false,
];
return [
'fallback' => true,
];
return [
'confirm_timeout' => 10800,
];
use Webauthn\AttestationStatement\AttestationStatementSupport;
use Webauthn\AttestationStatement\AndroidSafetyNetAttestationStatementSupport;
$this->app->extend(AttestationStatementSupport::class, function ($manager) {
$manager->add(new AndroidSafetyNetAttestationStatementSupport());
});
$this->app->bind(CounterChecker::class, function () {
return new \App\WebAuthn\MyCountChecker;
});
namespace App\WebAuthn;
use Webauthn\Counter\CounterChecker;
use App\Exceptions\WebAuthn\CredentialCloned;
use Webauthn\PublicKeyCredentialSource as Credentials;
class MyCountChecker implements CounterChecker
{
public function check(Credentials $credentials, int $currentCounter) : void
{
if ($credentials->getCounter() <= $currentCounter) {
throw new CredentialCloned($credentials);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.