2017 © Pedro Peláez
 

library two-factor-api

Provides two-factor authenticaton for Laravel

image

iago-effting/two-factor-api

Provides two-factor authenticaton for Laravel

  • Wednesday, November 18, 2015
  • by iagoEffting
  • Repository
  • 1 Watchers
  • 2 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Code Climate Scrutinizer Code Quality Build Status, (*1)

TwoFactorAPI

Two Factor API is a library to improve security authentication APIs. We use the system OTP (one-time password) a password that expires after some time. This implementation uses Google Autenticator to generate passwords in your mobile application., (*2)

How does it work: https://www.google.com/landing/2step/#tab=how-it-works, (*3)

Requirements

  • PHP 5.4+

Compatibility

  • Laravel 5.1+

Installing

1. Dependency

composer require iago-effting/two-factor-api

or manually, (*4)

{
    "require": {
        "iago-effting/two-factor-api": "dev-master"
    }
}

2. Provider

Add Service Provider and Facade to your config/app.php, (*5)

IagoEffting\TwoFactorAPI\Providers\TwoFactorApiServiceProvider::class
...
'TwoFactor'  => \IagoEffting\TwoFactorAPI\Facades\TwoFactor::class
```


### 3. Middleware
Add middleware to your `app\Http\kernel.php` in variable `$routeMiddleware`
```
// Access using TwoFactor
'needTwoFactor' => \IagoEffting\TwoFactorAPI\Middleware\TwoFactorAuthenticate::class,
```
### 4. User Class
On your User class, add the trait IagoEffting\TwoFactorAPI\Traits\HasTwoFacto to enable the creation of secret key:
```
namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Artesaos\Defender\Traits\HasDefender;
use IagoEffting\TwoFactorAPI\Traits\HasTwoFactor;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{

  use Authenticatable, CanResetPassword, HasTwoFactor;
...
```

### 5. Publishing configuration file and migrations
Publish the configs and migrates
```
php artisan vendor:publish
```

Run migrate

php artisan migrate, (*6)


## Usage ### Facade Generate secret key

TwoFactor::generateKey(); => 53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5, (*7)


Generate QR Code for synchronize in your Google Authentica

TwoFactor::generateQrCode(['mail' => 'iago.effting@gmail.com', 'key' => '53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5']) => https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FiNeural%3Aiago2222marina%40gmail.com%3Fsecret%3D53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5%26issuer%3DiNeural, (*8)


Verify that the key generated by Google Authenticator

TwoFactor::verifyKey($user, $secret); => true, (*9)


Attach in a User

$secret = new Secret(); $secret->key = TwoFactor::generateKey();, (*10)

$user = User::find(1); $user->secret()->save($secret); ```, (*11)

The Versions

18/11 2015

dev-master

9999999-dev

Provides two-factor authenticaton for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Iago Effting

14/10 2015

v0.0.26

0.0.26.0

Provides two-factor authenticaton for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Iago Effting