October 21, 2024
Chicago 12, Melborne City, USA
PHP

How to enable SMS 2FA in laravel filament dashboard using a custom endpoint not a known SMS service providers?


the problem I’m facing is: I want to use an endpoint that sends sms messages in laravel filament dashboard login as a 2FA.
Thats my SMS endpoint, Is there is anyway to use this for 2FA in filament login?

<?php

namespace App;

use GuzzleHttp\Client;

trait OTPmessageTrait
{
    protected $client;
    protected $baseUrl="https://api.oursms.com/api-a/msgs";
    
    public function __construct()
    {
        $this->client = new Client();
    }

    public function sendOtp($recipients, $message)
    {
        try {
            $response = $this->client->post($this->baseUrl, [
                'form_params' => [
                    'username'  => env('SMS_API_USERNAME'),
                    'token'     => env('SMS_API_TOKEN'),
                    'src'       => env('SMS_API_SENDER_ID'),
                    'dests'     => $recipients, // Example: '96654XXXXXX,96656XXXXXX'
                    'body'      => $message,
                    'priority'  => 0,
                    'delay'     => 0,
                    'validity'  => 0,
                    'maxParts'  => 0,
                    'dlr'       => 0,
                    'prevDups'  => 0,
                ]
            ]);

            $responseBody = json_decode($response->getBody(), true);
            return $responseBody;
        } catch (\Exception $e) {
            return ['error' => $e->getMessage()];
        }
    }
}

i tried using this plugin vormkracht10/filament-2fa but i couldn’t custom it for my purpose. I’m trying breezy now too but if someone knows how to adjust these packages to do that please leave a solution. And if a laravel sms sender would help how can I use it in filament dashboard filament?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video