1 | <?php |
||
25 | class Google2FA extends Google2FAService |
||
26 | { |
||
27 | use Auth, Config, Request, Session; |
||
28 | |||
29 | protected $qrCodeBackend; |
||
30 | |||
31 | /** |
||
32 | * Construct the correct backend. |
||
33 | */ |
||
34 | 12 | protected function constructBackend(): void |
|
35 | { |
||
36 | 12 | switch ($this->getQRCodeBackend()) { |
|
37 | 12 | case Constants::QRCODE_IMAGE_BACKEND_SVG: |
|
38 | 12 | parent::__construct(new \BaconQrCode\Renderer\Image\SvgImageBackEnd()); |
|
39 | 12 | break; |
|
40 | |||
41 | case Constants::QRCODE_IMAGE_BACKEND_EPS: |
||
42 | parent::__construct(new \BaconQrCode\Renderer\Image\EpsImageBackEnd()); |
||
43 | break; |
||
44 | |||
45 | case Constants::QRCODE_IMAGE_BACKEND_IMAGEMAGICK: |
||
46 | default: |
||
47 | parent::__construct(); |
||
48 | break; |
||
49 | } |
||
50 | 12 | } |
|
51 | |||
52 | /** |
||
53 | * Set the QRCode Backend. |
||
54 | * |
||
55 | * @param string $qrCodeBackend |
||
56 | * |
||
57 | * @return self |
||
58 | */ |
||
59 | public function setQrCodeBackend(string $qrCodeBackend) |
||
60 | { |
||
61 | $this->qrCodeBackend = $qrCodeBackend; |
||
62 | |||
63 | return $this; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Authenticator constructor. |
||
68 | * |
||
69 | * @param IlluminateRequest $request |
||
70 | */ |
||
71 | 12 | public function __construct(IlluminateRequest $request) |
|
77 | |||
78 | /** |
||
79 | * Authenticator boot. |
||
80 | * |
||
81 | * @param $request |
||
82 | * |
||
83 | * @return Google2FA |
||
84 | */ |
||
85 | 12 | public function boot($request) |
|
91 | |||
92 | /** |
||
93 | * The QRCode Backend. |
||
94 | * |
||
95 | * @return mixed |
||
96 | */ |
||
97 | 12 | public function getQRCodeBackend() |
|
102 | |||
103 | /** |
||
104 | * Get the user Google2FA secret. |
||
105 | * |
||
106 | * @throws InvalidSecretKey |
||
107 | * |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 8 | protected function getGoogle2FASecretKey() |
|
114 | |||
115 | /** |
||
116 | * Check if the 2FA is activated for the user. |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | 8 | public function isActivated() |
|
126 | |||
127 | /** |
||
128 | * Store the old OTP timestamp. |
||
129 | * |
||
130 | * @param $key |
||
131 | * |
||
132 | * @return mixed |
||
133 | */ |
||
134 | 5 | protected function storeOldTimestamp($key) |
|
140 | |||
141 | /** |
||
142 | * Get the previous OTP timestamp. |
||
143 | * |
||
144 | * @return null|mixed |
||
145 | */ |
||
146 | 6 | protected function getOldTimestamp() |
|
152 | |||
153 | /** |
||
154 | * Keep this OTP session alive. |
||
155 | */ |
||
156 | 4 | protected function keepAlive() |
|
162 | |||
163 | /** |
||
164 | * Get minutes since last activity. |
||
165 | * |
||
166 | * @return int |
||
167 | */ |
||
168 | 1 | protected function minutesSinceLastActivity() |
|
174 | |||
175 | /** |
||
176 | * Check if no user is authenticated using OTP. |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | 7 | protected function noUserIsAuthenticated() |
|
184 | |||
185 | /** |
||
186 | * Check if OTP has expired. |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | 4 | protected function passwordExpired() |
|
204 | |||
205 | /** |
||
206 | * Verifies, in the current session, if a 2fa check has already passed. |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 7 | protected function twoFactorAuthStillValid() |
|
216 | |||
217 | /** |
||
218 | * Check if the module is enabled. |
||
219 | * |
||
220 | * @return mixed |
||
221 | */ |
||
222 | 7 | protected function isEnabled() |
|
226 | |||
227 | /** |
||
228 | * Set current auth as valid. |
||
229 | */ |
||
230 | 5 | public function login() |
|
237 | |||
238 | /** |
||
239 | * OTP logout. |
||
240 | */ |
||
241 | 3 | public function logout() |
|
249 | |||
250 | /** |
||
251 | * Update the current auth time. |
||
252 | */ |
||
253 | 5 | protected function updateCurrentAuthTime() |
|
257 | |||
258 | /** |
||
259 | * Verify the OTP. |
||
260 | * |
||
261 | * @param $secret |
||
262 | * @param $one_time_password |
||
263 | * |
||
264 | * @return mixed |
||
265 | */ |
||
266 | 6 | public function verifyGoogle2FA($secret, $one_time_password) |
|
276 | |||
277 | /** |
||
278 | * Verify the OTP and store the timestamp. |
||
279 | * |
||
280 | * @param $one_time_password |
||
281 | * |
||
282 | * @return mixed |
||
283 | */ |
||
284 | 5 | protected function verifyAndStoreOneTimePassword($one_time_password) |
|
293 | |||
294 | /** |
||
295 | * Generate token, store in session. |
||
296 | */ |
||
297 | 5 | private function generateCookieToken(): void |
|
332 | } |
||
333 |