Laravel Auth

PHP MIT

Laravel Auth by GhostCompiler adds advanced authentication for Laravel with TOTP 2FA, passkeys via WebAuthn, OTP channels (email, SMS, WhatsApp), trusted devices, and tenant-aware social login.

Stars
2
Forks
0
Downloads
N/A
Open Issues
0
Files main

Repository Files

Loading file structure...
src/OTP/Transport/BaseOtpTransport.php
<?php

declare(strict_types=1);

namespace GhostCompiler\LaravelAuth\OTP\Transport;

use GhostCompiler\LaravelAuth\Contracts\OtpTransport;
use GhostCompiler\LaravelAuth\Models\OtpChallenge;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Http;
use RuntimeException;

abstract class BaseOtpTransport implements OtpTransport
{
    public function verifyCode(Authenticatable $user, OtpChallenge $challenge, string $code, array $context = []): bool
    {
        return true;
    }

    /**
     * @param  array<string, mixed>  $options
     * @return array<string, mixed>
     */
    protected function postJson(string $url, array $payload, array $options = []): array
    {
        $request = Http::acceptJson();

        if (isset($options['basic'])) {
            [$username, $password] = $options['basic'];
            $request = $request->withBasicAuth($username, $password);
        }

        if (isset($options['headers']) && is_array($options['headers'])) {
            $request = $request->withHeaders($options['headers']);
        }

        $response = $request->post($url, $payload);

        if ($response->failed()) {
            throw new RuntimeException('OTP provider request failed.');
        }

        return $response->json() ?? [];
    }
}