mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-25 06:24:07 +02:00
Apply Laravel Pint fixes
This commit is contained in:
parent
05a39b6501
commit
65c4bbc496
@ -16,11 +16,11 @@ class WebauthnCredentialBroker extends PasswordBroker
|
||||
* @param \Closure|null $callback
|
||||
* @return string
|
||||
*/
|
||||
public function sendResetLink(array $credentials, Closure $callback = null) : string
|
||||
public function sendResetLink(array $credentials, Closure $callback = null): string
|
||||
{
|
||||
$user = $this->getUser($credentials);
|
||||
|
||||
if (! $user instanceof WebAuthnAuthenticatable) {
|
||||
if (!$user instanceof WebAuthnAuthenticatable) {
|
||||
return static::INVALID_USER;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ class WebauthnCredentialBroker extends PasswordBroker
|
||||
{
|
||||
$user = $this->validateReset($credentials);
|
||||
|
||||
if (! $user instanceof CanResetPasswordContract || ! $user instanceof WebAuthnAuthenticatable) {
|
||||
if (!$user instanceof CanResetPasswordContract || !$user instanceof WebAuthnAuthenticatable) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class Helpers
|
||||
* @param string $extension
|
||||
* @return string The filename
|
||||
*/
|
||||
public static function getUniqueFilename(string $extension) : string
|
||||
public static function getUniqueFilename(string $extension): string
|
||||
{
|
||||
return Str::random(40) . '.' . $extension;
|
||||
}
|
||||
@ -23,7 +23,7 @@ class Helpers
|
||||
* @param string|null $release
|
||||
* @return string|false
|
||||
*/
|
||||
public static function cleanVersionNumber(?string $release) : string|false
|
||||
public static function cleanVersionNumber(?string $release): string|false
|
||||
{
|
||||
// We use the regex for semver detection (see https://semver.org/)
|
||||
return preg_match('/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/', $release, $version) ? $version[0] : false;
|
||||
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
// namespace App\Http\Controllers\Auth;
|
||||
|
||||
// use App\Http\Controllers\Controller;
|
||||
// use App\Providers\RouteServiceProvider;
|
||||
// // use DarkGhostHunter\Larapass\Http\ConfirmsWebAuthn;
|
||||
|
||||
// class WebAuthnConfirmController extends Controller
|
||||
// {
|
||||
// // use ConfirmsWebAuthn;
|
||||
|
||||
// /*
|
||||
// |--------------------------------------------------------------------------
|
||||
// | Confirm Device Controller
|
||||
// |--------------------------------------------------------------------------
|
||||
// |
|
||||
// | This controller is responsible for handling WebAuthn confirmations and
|
||||
// | uses a simple trait to include the behavior. You're free to explore
|
||||
// | this trait and override any functions that require customization.
|
||||
// |
|
||||
// */
|
||||
|
||||
// /**
|
||||
// * Where to redirect users when the intended url fails.
|
||||
// *
|
||||
// * @var string
|
||||
// */
|
||||
// protected $redirectTo = RouteServiceProvider::HOME;
|
||||
// }
|
@ -39,19 +39,13 @@ class WebAuthnDeviceLostController extends Controller
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
protected function sendRecoveryLinkFailedResponse(Request $request, string $response)
|
||||
{
|
||||
if ($request->wantsJson()) {
|
||||
throw ValidationException::withMessages(['email' => [trans($response)]]);
|
||||
}
|
||||
|
||||
return back()
|
||||
->withInput($request->only('email'))
|
||||
->withErrors(['email' => trans($response)]);
|
||||
throw ValidationException::withMessages(['email' => [trans($response)]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +53,7 @@ class WebAuthnDeviceLostController extends Controller
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function sendRecoveryLinkResponse(Request $request, string $response)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ class WebAuthnLoginController extends Controller
|
||||
* @param \Laragear\WebAuthn\Http\Requests\AssertionRequest $request
|
||||
* @return \Illuminate\Contracts\Support\Responsable|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function options(AssertionRequest $request) : Responsable|JsonResponse
|
||||
public function options(AssertionRequest $request): Responsable|JsonResponse
|
||||
{
|
||||
switch (config('webauthn.user_verification')) {
|
||||
case WebAuthn::USER_VERIFICATION_DISCOURAGED:
|
||||
|
@ -17,7 +17,7 @@ class WebAuthnRegisterController extends Controller
|
||||
* @param \Laragear\WebAuthn\Http\Requests\AttestationRequest $request
|
||||
* @return \Illuminate\Contracts\Support\Responsable
|
||||
*/
|
||||
public function options(AttestationRequest $request) : Responsable
|
||||
public function options(AttestationRequest $request): Responsable
|
||||
{
|
||||
switch (config('webauthn.user_verification')) {
|
||||
case WebAuthn::USER_VERIFICATION_DISCOURAGED:
|
||||
@ -40,7 +40,7 @@ class WebAuthnRegisterController extends Controller
|
||||
* @param \Laragear\WebAuthn\Http\Requests\AttestedRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function register(AttestedRequest $request) : Response
|
||||
public function register(AttestedRequest $request): Response
|
||||
{
|
||||
$request->save();
|
||||
|
||||
|
@ -142,13 +142,13 @@ class TwoFAccount extends Model implements Sortable
|
||||
parent::boot();
|
||||
|
||||
static::saving(function (TwoFAccount $twofaccount) {
|
||||
if (! $twofaccount->legacy_uri) {
|
||||
if (!$twofaccount->legacy_uri) {
|
||||
$twofaccount->legacy_uri = $twofaccount->getURI();
|
||||
}
|
||||
if ($twofaccount->otp_type == TwoFAccount::TOTP && ! $twofaccount->period) {
|
||||
if ($twofaccount->otp_type == TwoFAccount::TOTP && !$twofaccount->period) {
|
||||
$twofaccount->period = TwoFAccount::DEFAULT_PERIOD;
|
||||
}
|
||||
if ($twofaccount->otp_type == TwoFAccount::HOTP && ! $twofaccount->counter) {
|
||||
if ($twofaccount->otp_type == TwoFAccount::HOTP && !$twofaccount->counter) {
|
||||
$twofaccount->counter = TwoFAccount::DEFAULT_COUNTER;
|
||||
}
|
||||
});
|
||||
@ -253,7 +253,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
*/
|
||||
public function setDigitsAttribute($value)
|
||||
{
|
||||
$this->attributes['digits'] = ! $value ? 6 : $value;
|
||||
$this->attributes['digits'] = !$value ? 6 : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +264,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
*/
|
||||
public function setAlgorithmAttribute($value)
|
||||
{
|
||||
$this->attributes['algorithm'] = ! $value ? self::SHA1 : strtolower($value);
|
||||
$this->attributes['algorithm'] = !$value ? self::SHA1 : strtolower($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,7 +275,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
*/
|
||||
public function setPeriodAttribute($value)
|
||||
{
|
||||
$this->attributes['period'] = ! $value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value;
|
||||
$this->attributes['period'] = !$value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,15 +329,15 @@ class TwoFAccount extends Model implements Sortable
|
||||
$OtpDto->otp_type = $this->otp_type;
|
||||
$OtpDto->generated_at = time();
|
||||
$OtpDto->password = $this->otp_type === self::TOTP
|
||||
? $this->generator->at($OtpDto->generated_at)
|
||||
: SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret)));
|
||||
? $this->generator->at($OtpDto->generated_at)
|
||||
: SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret)));
|
||||
$OtpDto->period = $this->period;
|
||||
}
|
||||
|
||||
Log::info(sprintf('New OTP generated for TwoFAccount (%s)', $this->id ? 'id:' . $this->id : 'preview'));
|
||||
|
||||
return $OtpDto;
|
||||
} catch (\Exception|\Throwable $ex) {
|
||||
} catch (\Exception | \Throwable $ex) {
|
||||
Log::error('An error occured, OTP generation aborted');
|
||||
// Currently a secret issue is the only possible exception thrown by OTPHP for this stack
|
||||
// so it is Ok to send the corresponding 2FAuth exception.
|
||||
@ -374,7 +374,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
$this->enforceAsSteam();
|
||||
}
|
||||
|
||||
if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) {
|
||||
if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
|
||||
$this->icon = $this->getDefaultIcon();
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
// First we instanciate the OTP generator
|
||||
try {
|
||||
$this->generator = Factory::loadFromProvisioningUri($uri);
|
||||
} catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) {
|
||||
} catch (\Assert\AssertionFailedException | \Assert\InvalidArgumentException | \Exception | \Throwable $ex) {
|
||||
throw ValidationException::withMessages([
|
||||
'uri' => __('validation.custom.uri.regex', ['attribute' => 'uri']),
|
||||
]);
|
||||
@ -401,7 +401,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
|
||||
// As loadFromProvisioningUri() accept URI without label (nor account nor service) we check
|
||||
// that the account is set
|
||||
if (! $this->generator->getLabel()) {
|
||||
if (!$this->generator->getLabel()) {
|
||||
Log::error('URI passed to fillWithURI() must contain a label');
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
@ -426,7 +426,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
$this->icon = $this->storeImageAsIcon($this->generator->getParameter('image'));
|
||||
}
|
||||
|
||||
if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) {
|
||||
if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
|
||||
$this->icon = $this->getDefaultIcon();
|
||||
}
|
||||
|
||||
@ -454,7 +454,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* Sets model attributes to STEAM values
|
||||
*/
|
||||
private function enforceAsSteam() : void
|
||||
private function enforceAsSteam(): void
|
||||
{
|
||||
$this->otp_type = self::STEAM_TOTP;
|
||||
$this->digits = 5;
|
||||
@ -477,7 +477,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* Returns an otpauth URI built with model attribute values
|
||||
*/
|
||||
public function getURI() : string
|
||||
public function getURI(): string
|
||||
{
|
||||
$this->initGenerator();
|
||||
|
||||
@ -490,7 +490,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
* @throws UnsupportedOtpTypeException The defined OTP type is not supported
|
||||
* @throws InvalidOtpParameterException One OTP parameter is invalid
|
||||
*/
|
||||
private function initGenerator() : void
|
||||
private function initGenerator(): void
|
||||
{
|
||||
try {
|
||||
switch ($this->otp_type) {
|
||||
@ -529,7 +529,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
} catch (UnsupportedOtpTypeException $exception) {
|
||||
Log::error(sprintf('%s is not an OTP type supported by the current generator', $this->otp_type));
|
||||
throw $exception;
|
||||
} catch (\Exception|\Throwable $exception) {
|
||||
} catch (\Exception | \Throwable $exception) {
|
||||
throw new InvalidOtpParameterException($exception->getMessage());
|
||||
}
|
||||
}
|
||||
@ -573,7 +573,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
return $newFilename;
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
catch (\Exception|\Throwable $ex) {
|
||||
catch (\Exception | \Throwable $ex) {
|
||||
Log::error(sprintf('Icon storage failed: %s', $ex->getMessage()));
|
||||
|
||||
return null;
|
||||
@ -596,7 +596,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* Returns an acceptable value
|
||||
*/
|
||||
private function decryptOrReturn(mixed $value) : mixed
|
||||
private function decryptOrReturn(mixed $value): mixed
|
||||
{
|
||||
// Decipher when needed
|
||||
if (Settings::get('useEncryption') && $value) {
|
||||
@ -613,7 +613,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* Encrypt a value
|
||||
*/
|
||||
private function encryptOrReturn(mixed $value) : mixed
|
||||
private function encryptOrReturn(mixed $value): mixed
|
||||
{
|
||||
// should be replaced by laravel 8 attribute encryption casting
|
||||
return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;
|
||||
|
@ -60,7 +60,7 @@ class LogoService
|
||||
$domain = $this->tfas->get($this->cleanDomain(strval($serviceName)));
|
||||
$logoFilename = $domain . '.svg';
|
||||
|
||||
if ($domain && ! Storage::disk('logos')->exists($logoFilename)) {
|
||||
if ($domain && !Storage::disk('logos')->exists($logoFilename)) {
|
||||
$this->fetchLogo($logoFilename);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ class LogoService
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setTfaCollection() : void
|
||||
protected function setTfaCollection(): void
|
||||
{
|
||||
// We fetch a fresh tfaDirectory if necessary to prevent too many API calls
|
||||
if (Storage::disk('logos')->exists(self::TFA_JSON)) {
|
||||
@ -93,17 +93,18 @@ class LogoService
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cacheTfaDirectorySource() : void
|
||||
protected function cacheTfaDirectorySource(): void
|
||||
{
|
||||
try {
|
||||
$response = Http::retry(3, 100)->get(self::TFA_URL);
|
||||
|
||||
$coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) /** @phpstan-ignore-line */
|
||||
->mapWithKeys(function ($item, $key) {
|
||||
return [
|
||||
strtolower(head($item)) => $item[1]['domain'],
|
||||
];
|
||||
});
|
||||
$coll = collect(json_decode(htmlspecialchars_decode($response->body()), true))
|
||||
/** @phpstan-ignore-line */
|
||||
->mapWithKeys(function ($item, $key) {
|
||||
return [
|
||||
strtolower(head($item)) => $item[1]['domain'],
|
||||
];
|
||||
});
|
||||
|
||||
Storage::disk('logos')->put(self::TFA_JSON, $coll->toJson())
|
||||
? Log::info('Fresh tfa.json saved to logos dir')
|
||||
@ -119,7 +120,7 @@ class LogoService
|
||||
* @param string $logoFile Logo filename to fetch
|
||||
* @return void
|
||||
*/
|
||||
protected function fetchLogo(string $logoFile) : void
|
||||
protected function fetchLogo(string $logoFile): void
|
||||
{
|
||||
try {
|
||||
$response = Http::retry(3, 100)
|
||||
@ -141,7 +142,7 @@ class LogoService
|
||||
* @param string $domain
|
||||
* @return string Optimized domain name
|
||||
*/
|
||||
protected function cleanDomain(string $domain) : string
|
||||
protected function cleanDomain(string $domain): string
|
||||
{
|
||||
return strtolower(str_replace(['+'], ['plus'], $domain));
|
||||
}
|
||||
@ -153,7 +154,7 @@ class LogoService
|
||||
* @param string $iconFilename
|
||||
* @return bool Weither the copy succed or not
|
||||
*/
|
||||
protected function copyToIcons($logoFilename, $iconFilename) : bool
|
||||
protected function copyToIcons($logoFilename, $iconFilename): bool
|
||||
{
|
||||
return Storage::disk('icons')->put($iconFilename, Storage::disk('logos')->get($logoFilename));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class GoogleAuthMigrator extends Migrator
|
||||
* @param mixed $migrationPayload migration uri provided by Google Authenticator export feature
|
||||
* @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts
|
||||
*/
|
||||
public function migrate(mixed $migrationPayload) : Collection
|
||||
public function migrate(mixed $migrationPayload): Collection
|
||||
{
|
||||
try {
|
||||
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload)));
|
||||
|
@ -17,7 +17,7 @@ class PlainTextMigrator extends Migrator
|
||||
* @param mixed $migrationPayload
|
||||
* @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts
|
||||
*/
|
||||
public function migrate(mixed $migrationPayload) : Collection
|
||||
public function migrate(mixed $migrationPayload): Collection
|
||||
{
|
||||
$otpauthURIs = preg_split('~\R~', $migrationPayload);
|
||||
$otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) {
|
||||
|
@ -14,7 +14,7 @@ class ReleaseRadarService
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scheduledScan() : void
|
||||
public function scheduledScan(): void
|
||||
{
|
||||
if ((Settings::get('lastRadarScan') + (60 * 60 * 24 * 7)) < time()) {
|
||||
$this->newRelease();
|
||||
@ -26,7 +26,7 @@ class ReleaseRadarService
|
||||
*
|
||||
* @return false|string False if no new release, the new release number otherwise
|
||||
*/
|
||||
public function manualScan() : false|string
|
||||
public function manualScan(): false|string
|
||||
{
|
||||
return $this->newRelease();
|
||||
}
|
||||
@ -36,7 +36,7 @@ class ReleaseRadarService
|
||||
*
|
||||
* @return false|string False if no new release, the new release number otherwise
|
||||
*/
|
||||
protected function newRelease() : false|string
|
||||
protected function newRelease(): false|string
|
||||
{
|
||||
if ($latestReleaseData = json_decode($this->getLatestReleaseData())) {
|
||||
|
||||
@ -62,7 +62,7 @@ class ReleaseRadarService
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getLatestReleaseData() : string|null
|
||||
protected function getLatestReleaseData(): string|null
|
||||
{
|
||||
try {
|
||||
$response = Http::retry(3, 100)
|
||||
|
Loading…
x
Reference in New Issue
Block a user