Giter Club home page Giter Club logo

google2fa-qrcode's Introduction

Google2FA QRCode

Latest Stable Version License Code Quality Build

Downloads Coverage StyleCI PHP

QRCode For Google2FA

This is package is Goole2FA integrated with a QRCode generator, providing an easy way to plot QRCode for your two factor authentication. For documentation related to Google2FA, please check the documentation of the main package.

Requirements

  • PHP 5.4+

Installing

Use Composer to install it:

composer require pragmarx/google2fa-qrcode

Using It

Instantiate it directly

use PragmaRX\Google2FAQRCode\Google2FA;
    
$google2fa = new Google2FA();
    
return $google2fa->generateSecretKey();

Generating QRCodes

The securer way of creating QRCode is to do it yourself or using a library. First you have to install the BaconQrCode package, as stated above, then you just have to generate the inline string using:

$inlineUrl = $google2fa->getQRCodeInline(
    $companyName,
    $companyEmail,
    $secretKey
);

And use it in your blade template this way:

<img src="{{ $inlineUrl }}">
$secretKey = $google2fa->generateSecretKey(16, $userId);

Show the QR Code to your user, via Google Apis

It's insecure to use it via Google Apis, so you have to enable it before using it.

$google2fa->setAllowInsecureCallToGoogleApis(true);

$google2fa_url = $google2fa->getQRCodeGoogleUrl(
    'YourCompany',
    $user->email,
    $user->google2fa_secret
);

/// and in your view:

<img src="{{ $google2fa_url }}" alt="">

And they should see and scan the QR code to their applications:

QRCode

And to verify, you just have to:

$secret = $request->input('secret');

$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);

Replacing the QRCode rendering service

If you want to use a different service, you just have to

$google2fa->setQrcodeService(new YourService())
          ->getQRCodeInline(
              $companyName,
              $companyEmail,
              $secretKey
          );

Built-in QRCode rendering services

Beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes:

  • BaconQrCode: renders PNG by default, but requires the Imagick PHP extension. You can configure it to use different backends, but you'll have to instantiate it yourself.
  • chillerlan/php-qrcode: renders SVG by default and don't require the Imagick PHP extension, but can also generate other formats, which may require Imagick.

Using a diffent image backend

$google2fa->setQrcodeService(
    new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);

// or 

$google2fa = new Google2FA(
    new Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);

Tests

The package tests were written with PHPUnit.

Authors

License

Google2FAQRCode is licensed under the MIT License - see the LICENSE file for details.

Contributing

Pull requests and issues are more than welcome.

google2fa-qrcode's People

Contributors

antonioribeiro avatar eusonlito avatar kartavik avatar mauriciofauth avatar mrtus avatar sergejostir avatar

Stargazers

 avatar  avatar  avatar  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.