PHP code example of secureprompt / laravel-device-approval
1. Go to this page and download the library: Download secureprompt/laravel-device-approval 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/ */
secureprompt / laravel-device-approval example snippets
use SecurePrompt\Laravel\Concerns\UsesSecurePrompt;
use SecurePrompt\Laravel\Contracts\ApprovalSubject;
class User extends Authenticatable implements ApprovalSubject
{
use UsesSecurePrompt;
}
// ❌ WRONG — user is already logged in before device approval
Auth::attempt($credentials);
use Illuminate\Support\Facades\Auth;
use SecurePrompt\Laravel\Application\Session\BeginPendingAuthentication;
use SecurePrompt\Laravel\Application\Session\StartApprovalFromPendingAuthentication;
$provider = Auth::guard('web')->getProvider();
$user = $provider->retrieveByCredentials($credentials);
if ($user === null || ! $provider->validateCredentials($user, $credentials)) {
abort(401);
}
app(BeginPendingAuthentication::class)->begin($user, 'web');
$started = app(StartApprovalFromPendingAuthentication::class)->start();
// Keep requester proof in the Laravel session — never in the query string.
use SecurePrompt\Laravel\Application\TrustedDevice\EnrollTrustedDevice;
use SecurePrompt\Laravel\Domain\ValueObjects\DeviceIdentifier;
$enrolled = app(EnrollTrustedDevice::class)->enroll(
$user->securePromptSubjectReference(),
DeviceIdentifier::from('phone-1'),
now()->toDateTimeImmutable(),
);
// Deliver $enrolled->credential() once. Never store plaintext in the database.