Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xruff/totpauth
Nette extension for Time-Based One-Time Password Algorithm
https://github.com/xruff/totpauth
2fa authentication nette nette-component nette-framework qr qrcode
Last synced: about 1 month ago
JSON representation
Nette extension for Time-Based One-Time Password Algorithm
- Host: GitHub
- URL: https://github.com/xruff/totpauth
- Owner: XRuff
- License: mit
- Created: 2017-08-30T23:19:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-28T21:59:02.000Z (over 4 years ago)
- Last Synced: 2024-11-13T14:51:49.759Z (about 2 months ago)
- Topics: 2fa, authentication, nette, nette-component, nette-framework, qr, qrcode
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
TotpAuth
======Nette extension for Time-Based One-Time Password Algorithm
Requirements
------------Package requires PHP 7.0 or higher
- [tracy/tracy](https://github.com/tracy/tracy)
- [xruff/basedbmodel](https://github.com/xruff/basedbmodel)
- [oops/totp-authenticator](https://github.com/oops/totp-authenticator)
- [guzzlehttp/guzzle](https://github.com/oops/totp-authenticator)Installation
------------The best way to install XRuff/TotpAuth is using [Composer](http://getcomposer.org/):
```sh
$ composer require xruff/totpAuth
```Scenario
------------* logged user activate 2FA in account settings:
* see QR core
* scan it with [mobile application](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=cs)
* and click "Confirm Code" button
* next login to your application:
* user log in standard way (login + password...) and see second login page with form with one field
* provide code from Authenticator mobile aplication
* pass through if provided code is rightDocumentation
------------Assumptions:
* create table `qr` in database, use schema from file `sql/qr.sql`
* `$user->indentity` have to contain properties `id` and `username`Configuration in config.neon.
```yml
extensions:
totpAuth: XRuff\TotpAuth\DI\TotpAuthExtensiontotpAuth:
issuer: NameOfMyApp # mandatory
identityKey: login # optional, Default is 'login' eg $user->identity->login
timeWindow: 1 # optional - time tolerance
codeSize: '300x300' # optional - size ofgenerated QR code
```Presenter:
```php
use XRuff\TotpAuth\Auth;
use Nette\Application\UI;class HomepagePresenter extends Nette\Application\UI\Presenter
{
/** @var Auth $auth */
public $auth;public function __construct(Auth $auth)
{
$this->auth = $auth;
}public function renderDefault() {
$this->template->qrCode = $this->auth->getQrBase64();
}public function handleSaveUrl()
{
$this->auth->saveSecret();
$this->redirect('this');
}public function handleResetUrl()
{
$this->auth->resetSecret();
$this->redirect('this');
}protected function createComponentCodeForm()
{
$form = new UI\Form;
$form->addText('code', 'Code');
$form->addSubmit('submit', 'Auth me');
$form->onSuccess[] = [$this, 'codeFormSucceeded'];
return $form;
}public function codeFormSucceeded(UI\Form $form, $values)
{
if ($this->auth->verify($values->code)) {
$this->flashMessage('Success!');
} else {
$this->flashMessage('Wrong code.');
}
$this->redirect('this');
}
}
```default.latte:
```smarty
...
{if $qrCode}
Confirm Code (have been added to Mobile Authenticator App)
{else}
{control codeForm}
Reset auth code
{/if}
...
```-----
Repository [https://github.com/XRuff/TotpAuth](https://github.com/XRuff/TotpAuth).