Add automatic icon retrieval for Steam account

This commit is contained in:
Bubka 2022-07-07 11:43:23 +02:00
parent e03ec30040
commit b01718f2e8

View File

@ -370,7 +370,7 @@ public function getOTP() : TotpDto|HotpDto
*
* @return $this
*/
public function fillWithOtpParameters(array $parameters, bool $isSteamTotp = false)
public function fillWithOtpParameters(array $parameters)
{
$this->otp_type = Arr::get($parameters, 'otp_type');
$this->account = Arr::get($parameters, 'account');
@ -384,7 +384,7 @@ public function fillWithOtpParameters(array $parameters, bool $isSteamTotp = fal
$this->initGenerator();
if ($isSteamTotp) {
if ($this->otp_type === self::STEAM_TOTP || strtolower($this->service) === 'steam') {
$this->enforceAsSteam();
}
@ -431,12 +431,11 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false)
$this->counter = $this->generator->hasParameter('counter') ? $this->generator->getParameter('counter') : null;
$this->legacy_uri = $uri;
if ($isSteamTotp) {
if ($isSteamTotp || strtolower($this->service) === 'steam') {
$this->enforceAsSteam();
}
if ( $this->generator->hasParameter('image') ) {
$this->icon = $this->storeTokenImageAsIcon();
else if ($this->generator->hasParameter('image')) {
$this->icon = $this->storeImageAsIcon($this->generator->getParameter('image'));
}
Log::info(sprintf('TwoFAccount filled with an URI'));
@ -454,6 +453,7 @@ private function enforceAsSteam()
$this->digits = 5;
$this->algorithm = self::SHA1;
$this->period = 30;
$this->icon = $this->storeImageAsIcon('https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/langfr-320px-Steam_icon_logo.svg.png');
}
@ -523,14 +523,14 @@ private function initGenerator()
}
/**
* Gets the image resource pointed by the generator image parameter and store it as an icon
* Gets the image resource pointed by the image url and store it as an icon
*
* @return string|null The filename of the stored icon or null if the operation fails
*/
private function storeTokenImageAsIcon()
private function storeImageAsIcon(string $url)
{
try {
$remoteImageURL = $this->generator->getParameter('image');
$remoteImageURL = $url;
$path_parts = pathinfo($remoteImageURL);
$newFilename = Str::random(40) . '.' . $path_parts['extension'];
$imageFile = self::IMAGELINK_STORAGE_PATH . $newFilename;