All Projects β†’ antonioribeiro β†’ Google2fa Laravel

antonioribeiro / Google2fa Laravel

Licence: mit
A One Time Password Authentication package, compatible with Google Authenticator for Laravel

Projects that are alternatives of or similar to Google2fa Laravel

Privacyidea
πŸ” multi factor authentication system (2FA, MFA, OTP Server)
Stars: ✭ 1,027 (+66.18%)
Mutual labels:  authentication, 2fa, two-factor-authentication
Authelia
The Single Sign-On Multi-Factor portal for web apps
Stars: ✭ 11,094 (+1695.15%)
Mutual labels:  authentication, 2fa, two-factor-authentication
Two Factor Bundle
[OUTDATED] Two-factor authentication for Symfony applications πŸ” (bunde version ≀ 4). Please use version 5 from https://github.com/scheb/2fa.
Stars: ✭ 388 (-37.22%)
Mutual labels:  authentication, 2fa, two-factor-authentication
Laravel Auth
A powerful authentication, authorization and verification package built on top of Laravel. It provides developers with Role Based Access Control, Two-Factor Authentication, Social Authentication, and much more, compatible Laravel’s standard API and fully featured out of the box.
Stars: ✭ 128 (-79.29%)
Mutual labels:  laravel, authentication, two-factor-authentication
2FAuth
A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
Stars: ✭ 664 (+7.44%)
Mutual labels:  two-factor-authentication, 2fa
Aws Mfa
Manage AWS MFA Security Credentials
Stars: ✭ 606 (-1.94%)
Mutual labels:  2fa, two-factor-authentication
mobileid
Mobile ID Sample Scripts
Stars: ✭ 13 (-97.9%)
Mutual labels:  two-factor-authentication, 2fa
2FAuth-iOS
One-Time Password Generator
Stars: ✭ 20 (-96.76%)
Mutual labels:  two-factor-authentication, 2fa
otp-java
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).
Stars: ✭ 107 (-82.69%)
Mutual labels:  two-factor-authentication, 2fa
mfaws
πŸ”’ AWS multi-factor authentication for the CLI
Stars: ✭ 38 (-93.85%)
Mutual labels:  two-factor-authentication, 2fa
Java Otp
A one-time password (HOTP/TOTP) library for Java
Stars: ✭ 265 (-57.12%)
Mutual labels:  2fa, two-factor-authentication
crystal-two-factor-auth
Two Factor Authentication Crystal code implementing the Time-based One-time Password Algorithm
Stars: ✭ 24 (-96.12%)
Mutual labels:  two-factor-authentication, 2fa
totp
Time-Based One-Time Password Code Generator
Stars: ✭ 76 (-87.7%)
Mutual labels:  two-factor-authentication, 2fa
recovery
Create recovery/backup codes for 2FA
Stars: ✭ 72 (-88.35%)
Mutual labels:  two-factor-authentication, 2fa
apache 2fa
Apache two-factor (2FA) authentication with Google Authenticator based on Time-based One-Time Password (TOTP) or HMAC-based one-time password (HOTP) Algorithms.
Stars: ✭ 63 (-89.81%)
Mutual labels:  two-factor-authentication, 2fa
2FA-Auth
Generating 2FA codes in your terminal
Stars: ✭ 23 (-96.28%)
Mutual labels:  two-factor-authentication, 2fa
Two Factor Auth
Generate 2FA tokens compatible with Google Authenticator
Stars: ✭ 352 (-43.04%)
Mutual labels:  2fa, two-factor-authentication
Permissionmanager
Admin interface for managing users, roles, permissions, using Backpack CRUD
Stars: ✭ 363 (-41.26%)
Mutual labels:  laravel, authentication
Otp.net
A .NET implementation of TOTP and HOTP for things like two-factor authentication codes.
Stars: ✭ 424 (-31.39%)
Mutual labels:  2fa, two-factor-authentication
open2fa
Two-factor authentication app with import/export for iOS and macOS. All codes encrypted with AES 256. FaceID & TouchID support included. Written with love in SwiftUI ❀️
Stars: ✭ 24 (-96.12%)
Mutual labels:  two-factor-authentication, 2fa

Google2FA for Laravel

Latest Stable Version License Code Quality Build

Downloads Coverage StyleCI PHP

Google Two-Factor Authentication Package for Laravel

Google2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HMAC-Based One-time Password (HOTP) algorithm specified in RFC 4226 and the Time-based One-time Password (TOTP) algorithm specified in RFC 6238.

This package is a Laravel bridge to Google2FA's PHP package.

The intent of this package is to create QRCodes for Google2FA and check user typed codes. If you need to create backup/recovery codes, please check below.

Recovery/Backup codes

if you need to create recovery or backup codes to provide a way for your users to recover a lost account, you can use the Recovery Package.

Demos, Example & Playground

Please check the Google2FA Package Playground.

playground

Here's an demo app showing how to use Google2FA: google2fa-example.

You can scan the QR code on this (old) demo page with a Google Authenticator app and view the code changing (almost) in real time.

Compatibility

Laravel Google2FA Google2FA-Laravel
4.2 <= 1.0.1
5.0-5.1 <= 1.0.1
5.2-6.x >= 2.0.0 >= 0.2.0

Before Google2FA 2.0 (Laravel 5.1) you have to install pragmarx/google2fa:~1.0, because this package was both a Laravel package and a PHP (agnostic).

Demo

Click here to see the middleware demo:

middleware

Installing

Use Composer to install it:

composer require pragmarx/google2fa-laravel

Installing on Laravel

Laravel 5.5 and above

You don't have to do anything else, this package autoloads the Service Provider and create the Alias, using the new Auto-Discovery feature.

Laravel 5.4 and below

Add the Service Provider and Facade alias to your app/config/app.php (Laravel 4.x) or config/app.php (Laravel 5.x):

PragmaRX\Google2FALaravel\ServiceProvider::class,

'Google2FA' => PragmaRX\Google2FALaravel\Facade::class,

Publish the config file

php artisan vendor:publish --provider="PragmaRX\Google2FALaravel\ServiceProvider"

Using It

Use the Facade

use Google2FA;

return Google2FA::generateSecretKey();

In Laravel you can use the IoC Container

$google2fa = app('pragmarx.google2fa');

return $google2fa->generateSecretKey();

Middleware

This package has a middleware which will help you code 2FA on your app. To use it, you just have to:

Add the middleware to your Kernel.php:

protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\Middleware::class,
];

Using it in one or more routes:

Route::get('/admin', function () {
    return view('admin.index');
})->middleware(['auth', '2fa']);

QRCode Backend

There are three available: imagemagick (default), svg and eps.

You can change it via config:

/*
 * Which image backend to use for generating QR codes?
 *
 * Supports imagemagick, svg and eps
 */
'qrcode_image_backend' => \PragmaRX\Google2FALaravel\Support\Constants::QRCODE_IMAGE_BACKEND_IMAGEMAGICK,

Or runtime:

Google2FA::setQRCodeBackend('svg');

Configuring the view

You can set your 'ask for a one time password' view in the config file (config/google2fa.php):

/**
 * One Time Password View
 */
'view' => 'google2fa.index',

And in the view you just have to provide a form containing the input, which is also configurable:

/**
 * One Time Password request input name
 */
'otp_input' => 'one_time_password',

Here's a form example:

    <form action="/google2fa/authenticate" method="POST">
        <input name="one_time_password" type="text">

        <button type="submit">Authenticate</button>
    </form>

One Time Password Lifetime

Usually an OTP lasts forever, until the user logs off your app, but, to improve application safety, you may want to re-ask, only for the Google OTP, from time to time. So you can set a number of minutes here:

/**
* Lifetime in minutes.
* In case you need your users to be asked for a new one time passwords from time to time.
*/

'lifetime' => 0, // 0 = eternal

Keep in mind that this uses the Laravel sessions in the background. If this number exceeds the value set in config('session.lifetime') you will still be logged out, even if your OTP lifetime has not expired.

And you can decide whether your OTP will be kept alive while your users are browsing the site or not:

/**
 * Renew lifetime at every new request.
 */

'keep_alive' => true,

Manually logging out from 2Fa

This command wil logout your user and redirect he/she to the 2FA form on the next request:

Google2FA::logout();

If you don't want to use the Facade, you may:

use PragmaRX\Google2FALaravel\Support\Authenticator;

(new Authenticator(request()))->logout();

Throttling / Lockout after X attempts

Unless you need something really fancy, you can probably use Laravel's route throttle middleware for that:

Route::get('/admin', function () {
    return view('admin.index');
})->middleware(['auth', '2fa', 'throttle']);

Stateless usage

$authenticator = app(Authenticator::class)->bootStateless($request);

if ($authenticator->isAuthenticated()) {
    // otp auth success!
}

You can also use a stateless middleware:

protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\MiddlewareStateless::class,
];

Events

The following events are fired:

  • EmptyOneTimePasswordReceived
  • LoggedOut
  • LoginFailed
  • LoginSucceeded
  • OneTimePasswordExpired
  • OneTimePasswordRequested

Documentation

Check the ReadMe file in the main Google2FA repository.

Tests

The package tests were written with phpspec.

Author

Antonio Carlos Ribeiro

License

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

Contributing

Pull requests and issues are more than welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].