PHP code example of padosoft / laravel-rebel-step-up
1. Go to this page and download the library: Download padosoft/laravel-rebel-step-up 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/ */
padosoft / laravel-rebel-step-up example snippets
use Illuminate\Support\Facades\Route;
Route::middleware(['auth', 'rebel.stepup:change-email'])
->post('/account/email', [AccountController::class, 'updateEmail']);
use Padosoft\Rebel\Core\Context\SecurityContext;
use Padosoft\Rebel\StepUp\RebelStepUp;
use Padosoft\Rebel\StepUp\StepUpContext;
public function updateEmail(Request $request, RebelStepUp $stepUp)
{
$ctx = new StepUpContext(
subject: $request->user(),
purpose: 'change-email',
security: SecurityContext::fromRequest($request),
);
if (! $stepUp->isConfirmed($ctx)) {
// start the challenge and tell the client to show the code form
$start = $stepUp->start($ctx);
return response()->json([
'step_up' => '
use Padosoft\Rebel\StepUp\Sca\TransactionContext;
$ctx = new StepUpContext(
subject: $request->user(),
purpose: 'checkout-credit-order',
security: SecurityContext::fromRequest($request),
transaction: new TransactionContext(
amount: 1250.00,
currency: 'EUR',
payee: 'ACME Srl',
orderRef: 'ORD-2026-0042',
),
);
$start = $stepUp->start($ctx); // computes and freezes the binding_hash
// …the user enters the code / uses the passkey…
$result = $stepUp->confirm($start->challengeId, $code, $ctx);
if (! $result->success) {
// $result->reason may be 'binding_mismatch' if amount/payee changed
return back()->withErrors(__('The transaction changed, please re-confirm.'));
}
// use the preferred available driver (e.g. passkey if the user has one)
$start = $stepUp->start($ctx);
// or explicitly force the email OTP fallback
$start = $stepUp->start($ctx, driverKey: 'email_otp');
// which drivers are usable RIGHT NOW for this user/purpose?
foreach ($stepUp->availableDrivers($ctx) as $driver) {
echo $driver->key();
}