11<?php namespace Atomx ;
22
3+ use Atomx \Exceptions \TotpRequiredException ;
34use Atomx \Resources \Login ;
45
56class MemoryAccountStore implements AccountStore {
67 protected $ token = null ;
7- protected $ username , $ password , $ apiBase ;
8+ protected $ username , $ password , $ totp , $ apiBase ;
89
910 /**
10- * @param string $username
11- * @param string $password
12- * @param string $apiBase
11+ * @param string|null $username
12+ * @param string|null $password
13+ * @param string|null $totp
14+ * @param string|null $apiBase
1315 */
14- public function __construct ($ username = null , $ password = null , $ apiBase = null )
16+ public function __construct ($ username = null , $ password = null , $ totp = null , $ apiBase = null )
1517 {
1618 $ this ->username = $ username ;
1719 $ this ->password = $ password ;
20+ $ this ->totp = $ totp ;
1821 $ this ->apiBase = $ apiBase ;
1922
2023 if ($ this ->apiBase == null )
2124 $ this ->apiBase = AtomxClient::API_BASE ;
2225 }
2326
2427 /**
25- * @return string| null
28+ * @return null|string
2629 */
2730 public function getToken ()
2831 {
@@ -43,8 +46,12 @@ protected function getTokenFromLogin()
4346 $ response = $ this ->getLoginClient ()->login ([
4447 'email ' => $ this ->getUsername (),
4548 'password ' => $ this ->getPassword (),
49+ 'totp ' => $ this ->getTotp ()
4650 ]);
4751
52+ if ($ response ['totp_required ' ])
53+ throw new TotpRequiredException ($ response );
54+
4855 return $ response ['auth_token ' ];
4956 }
5057
@@ -72,6 +79,11 @@ public function getPassword()
7279 return $ this ->password ;
7380 }
7481
82+ public function getTotp ()
83+ {
84+ return $ this ->totp ;
85+ }
86+
7587 /**
7688 * @return string
7789 */
0 commit comments