$otp_parameters) { // Storage::put('file.jpg', $contents); $parameters = array(); $parameters['otp_type'] = $otp_parameters['type'] == 'steam' ? TwoFAccount::STEAM_TOTP : $otp_parameters['type']; $parameters['service'] = $otp_parameters['issuer']; $parameters['account'] = $otp_parameters['name']; $parameters['secret'] = $otp_parameters['info']['secret']; $parameters['algorithm'] = $otp_parameters['info']['algo']; $parameters['digits'] = $otp_parameters['info']['digits']; $parameters['counter'] = $otp_parameters['info']['counter'] ?? null; $parameters['period'] = $otp_parameters['info']['period'] ?? null; try { $twofaccounts[$key] = new TwoFAccount; $twofaccounts[$key]->fillWithOtpParameters($parameters); } catch (\Exception $exception) { Log::error(sprintf('Cannot instanciate a TwoFAccount object with OTP parameters from imported item #%s', $key)); Log::error($exception->getMessage()); // The token failed to generate a valid account so we create a fake account to be returned. $fakeAccount = new TwoFAccount(); $fakeAccount->id = -2; $fakeAccount->otp_type = $otp_parameters['type']; // Only basic fields are filled to limit the risk of another exception. $fakeAccount->account = $otp_parameters['name']; $fakeAccount->service = $otp_parameters['issuer']; // The secret field is used to pass the error, not very clean but will do the job for now. $fakeAccount->secret = $exception->getMessage(); $twofaccounts[$key] = $fakeAccount; } } return collect($twofaccounts); } }