1. Go to this page and download the library: Download dcnl1980/authy library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Srmklive\Authy\Auth\TwoFactor\Authenticatable as TwoFactorAuthenticatable;
use Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable as TwoFactorAuthenticatableContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract,
TwoFactorAuthenticatableContract
use Authenticatable, Authorizable, CanResetPassword;
use Authenticatable, Authorizable, CanResetPassword, TwoFactorAuthenticatable;
protected $hidden = [
'two_factor_options'
];
/**
* Send the post-authentication response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return \Illuminate\Http\Response
*/
protected function authenticated(Request $request, Authenticatable $user)
{
if (Authy::getProvider()->isEnabled($user)) {
return $this->logoutAndRedirectToTokenScreen($request, $user);
}
return redirect()->intended($this->redirectPath());
}
/**
* Generate a redirect response to the two-factor token screen.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return \Illuminate\Http\Response
*/
protected function logoutAndRedirectToTokenScreen(Request $request, Authenticatable $user)
{
// Uncomment this line for Laravel 5.2+
//auth($this->getGuard())->logout();
// Uncomment this line for Laravel 5.1
// auth()->logout();
$request->session()->put('authy:auth:id', $user->id);
return redirect(url('auth/token'));
}
/**
* Show two-factor authentication page
*
* @return \Illuminate\Http\Response|\Illuminate\View\View
*/
public function getToken()
{
return session('authy:auth:id') ? view('auth.token') : redirect(url('login'));
}
/**
* Verify the two-factor authentication token.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postToken(Request $request)
{
$this->validate($request, ['token' => '
namespace App\Services;
use Exception;
use GuzzleHttp\Client as HttpClient;
use Srmklive\Authy\Contracts\Auth\TwoFactor\Provider as BaseProvider;
use Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable as TwoFactorAuthenticatable;
class MyAuthProvider implements BaseProvider
{
/**
* Array containing configuration data.
*
* @var array $config
*/
private $config;
/**
* Authy constructor.
*/
public function __construct()
{
// Add your configuration code here
}
/**
* Determine if the given user has two-factor authentication enabled.
*
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
* @return bool
*/
public function isEnabled(TwoFactorAuthenticatable $user)
{
// Add your code here
}
/**
* Register the given user with the provider.
*
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
* @param boolean $sms
* @return void
*/
public function register(TwoFactorAuthenticatable $user, $sms = false)
{
// Add your code here
}
/**
* Determine if the given token is valid for the given user.
*
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
* @param string $token
* @return bool
*/
public function tokenIsValid(TwoFactorAuthenticatable $user, $token)
{
// Add your code here
}
/**
* Delete the given user from the provider.
*
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
* @return bool
*/
public function delete(TwoFactorAuthenticatable $user)
{
// Add your code here
}
}