forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleAuthenticatorComponent.php
More file actions
83 lines (75 loc) · 2.35 KB
/
Copy pathGoogleAuthenticatorComponent.php
File metadata and controls
83 lines (75 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Controller\Component;
use Cake\Controller\Component;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Utility\Security;
use InvalidArgumentException;
use RobThree\Auth\TwoFactorAuth;
/**
* GoogleAuthenticator Component.
*
* @link https://github.com/RobThree/TwoFactorAuth
*/
class GoogleAuthenticatorComponent extends Component
{
/** @var \RobThree\Auth\TwoFactorAuth $tfa */
public $tfa;
/**
* initialize method
* @param array $config The config data
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
if (Configure::read('Users.GoogleAuthenticator.login')) {
$this->tfa = new TwoFactorAuth(
Configure::read('Users.GoogleAuthenticator.issuer'),
Configure::read('Users.GoogleAuthenticator.digits'),
Configure::read('Users.GoogleAuthenticator.period'),
Configure::read('Users.GoogleAuthenticator.algorithm'),
Configure::read('Users.GoogleAuthenticator.qrcodeprovider'),
Configure::read('Users.GoogleAuthenticator.rngprovider')
);
}
}
/**
* createSecret
* @return string base32 shared secret stored in users table
*/
public function createSecret()
{
return $this->tfa->createSecret();
}
/**
* verifyCode
* Verifying tfa code with shared secret
* @param string $secret of the user
* @param string $code from verification form
* @return bool
*/
public function verifyCode($secret, $code)
{
return $this->tfa->verifyCode($secret, $code);
}
/**
* getQRCodeImageAsDataUri
* @param string $issuer issuer
* @param string $secret secret
* @return string base64 string containing QR code for shared secret
*/
public function getQRCodeImageAsDataUri($issuer, $secret)
{
return $this->tfa->getQRCodeImageAsDataUri($issuer, $secret);
}
}