Git Product home page Git Product logo

phonable's Introduction

Roomies Phonable

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Roomies Phonable provides an abstraction layer to identify and verify phone numbers in your Laravel app. Phone verification can be used to help identify legitmate users of your app and also serve as a way to handle 2-factor authentication. Phonable provides implementations for a number of phone services including Prelude (previously Ding), Twilio, and Vonage.

Installation

You can install the package via Composer:

composer require roomies/phonable

You can publish the config file with:

php artisan vendor:publish --tag="phonable-config"

Read through the config file to understand the supported services and provide the correct configuration for your preferred services.

Identification

Identification is a way to gather more information about a phone number including the country of origin, phone number type and more. This feature is supported by Prelude and Vonage.

// Return an instance of \Roomies\Phonable\Identification\IdentificationResult
$result = Identification::get('+12125550000');

Alternatively you can pass an object that implements Roomies\Phonable\Contracts\PhoneIdentifiable - getIdentifiablePhoneNumber() should return the phone number in E.164 format.

use Roomies\Phonable\Facades\Identification;
use Roomies\Phonable\Contracts\PhoneIdentifiable;

class User implements PhoneIdentifiable
{
    /**
     * The identifiable phone number in E.164 format.
     */
    public function getIdentifiablePhoneNumber(): ?string
    {
        return '+12125550000';
    }
}

// Return an instance of \Roomies\Phonable\Identification\IdentificationResult
$result = Identification::get($user);

You can swap the driver out on the fly as necessary.

use Roomies\Phonable\Facades\Identification;

Identification::driver('prelude')->get($user);

Verification

Verification is a two-step process in sending a generated code to a phone number that then needs to be entered back into your app to complete the process. This ensures your user has timely access to the phone number provided. This feature is supported by Prelude, Twilio, and Vonage.

// Return an instance of \Roomies\Phonable\Verification\VerificationRequest
$request = Verification::send('+12125550000');

// Return an instance of \Roomies\Phonable\Verification\VerificationResult
$result = Verification::verify($request->id, 'code');

Alternatively you can pass an object that implements Roomies\Phonable\Contracts\PhoneVerifiable - getVerifiablePhoneNumber() should return the phone number in E.164 format and getVerifiableSession() should return the previously stored verification request ID.

use Roomies\Phonable\Facades\Verification;
use Roomies\Phonable\Contracts\PhoneIdentifiable;

class User implements PhoneVerifiable
{
    /**
     * The verifiable phone number in E.164 format.
     */
    public function getVerifiablePhoneNumber(): ?string
    {
        return '+12125550000';
    }

    /**
     * The current verification session identifier.
     */
    public function getVerifiableSession(): ?string
    {
        return $this->phone_verification_session;
    }
}

// Return an instance of \Roomies\Phonable\Verification\VerificationRequest
$request = Verification::send($user);

$user->update([
    'phone_verification_session' => $request->id,
]);

You will need to store the verification session ID as it will be used to complete the process.

When you receive the code from the user you can then call the verify method with the provided code. Roomies\Phonable\Verification\VerificationResult is a simple enum of the result.

use Roomies\Phonable\Verification\VerificationResult;

// Return an instance of \Roomies\Phonable\Verification\VerificationResult
$result = Verification::verify($user, 1234);

if ($result === VerificationResult::Successful) {
    $user->update([
        'phone_verified_at' => now(),
        'phone_verification_session' => null,
    ]);
}

You can swap the driver out on the fly as necessary.

use Roomies\Phonable\Facades\Verification;

Verification::driver('prelude')->send($user);

License

The MIT License (MIT). Please see License File for more information.

phonable's People

Contributors

dwightwatson avatar

Stargazers

Thomas Off avatar MarcS avatar Rifki Aria Gumelar avatar Ian Hawes avatar Miftah Shidiq avatar Daniel Rodrigues de Lima avatar Marcin Lewandowski avatar Github's AdjobiPierre avatar Aymerick Valette avatar Matias Berny avatar ziming avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.