Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow logging channel configuration for webauthn #432

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/webauthn.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@
'register' => 'webauthn::register',
],

/*
|--------------------------------------------------------------------------
| Webauthn logging
|--------------------------------------------------------------------------
|
| Here you may specify the channel to which Webauthn will log messages.
| This value should correspond with one of your loggers that is already
| present in your "logging" configuration file. If left as null, it will
| use the default logger for the application.
|
*/

'log' => null,

/*
|--------------------------------------------------------------------------
| Session name
Expand Down
3 changes: 1 addition & 2 deletions src/Services/Webauthn/CredentialAssertionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Auth\Authenticatable as User;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use LaravelWebauthn\Exceptions\ResponseMismatchException;
use Psr\Http\Message\ServerRequestInterface;
use Webauthn\AuthenticatorAssertionResponse;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
try {
return PublicKeyCredentialRequestOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
} catch (\Exception $e) {
Log::debug('Webauthn publickKey deserialize error', ['exception' => $e]);
app('webauthn.log')->debug('Webauthn publickKey deserialize error', ['exception' => $e]);
abort(404);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Services/Webauthn/CredentialAttestationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Auth\Authenticatable as User;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use LaravelWebauthn\Exceptions\ResponseMismatchException;
use Psr\Http\Message\ServerRequestInterface;
use Webauthn\AuthenticatorAttestationResponse;
Expand Down Expand Up @@ -73,7 +72,7 @@ protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
try {
return PublicKeyCredentialCreationOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
} catch (\Exception $e) {
Log::debug('Webauthn publicKey deserialize error', ['exception' => $e]);
app('webauthn.log')->debug('Webauthn publicKey deserialize error', ['exception' => $e]);
abort(404);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/WebauthnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use LaravelWebauthn\Auth\EloquentWebAuthnProvider;
use LaravelWebauthn\Contracts\DestroyResponse as DestroyResponseContract;
Expand Down Expand Up @@ -93,6 +92,7 @@
);

$this->app->bind(StatefulGuard::class, fn () => Auth::guard(config('webauthn.guard', null)));
$this->app->bind('webauthn.log', fn ($app) => $app['log']->channel(config('webauthn.log', config('logging.default'))));
}

/**
Expand Down Expand Up @@ -135,7 +135,7 @@
*/
protected function bindWebAuthnPackage(): void
{
$this->app->bind(PublicKeyCredentialSourceRepository::class, CredentialRepository::class);

Check failure on line 138 in src/WebauthnServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan (8.2)

Fetching class constant class of deprecated class Webauthn\PublicKeyCredentialSourceRepository.

$this->app->bind(
PackedAttestationStatementSupport::class,
Expand Down Expand Up @@ -184,36 +184,36 @@
fn ($app) => tap(new AttestationObjectLoader(
$app[AttestationStatementSupportManager::class]
), function ($loader) use ($app) {
$loader->setLogger($app['log']);
$loader->setLogger($app['webauthn.log']);
})
);

$this->app->bind(
CounterChecker::class,
fn ($app) => new ThrowExceptionIfInvalid($app['log'])
fn ($app) => new ThrowExceptionIfInvalid($app['webauthn.log'])
);

$this->app->bind(
AuthenticatorAttestationResponseValidator::class,
fn ($app) => tap(new AuthenticatorAttestationResponseValidator(
$app[AttestationStatementSupportManager::class],
$app[PublicKeyCredentialSourceRepository::class],

Check failure on line 200 in src/WebauthnServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan (8.2)

Fetching class constant class of deprecated class Webauthn\PublicKeyCredentialSourceRepository.
null,
$app[ExtensionOutputCheckerHandler::class]
), function ($responseValidator) use ($app) {
$responseValidator->setLogger($app['log']);
$responseValidator->setLogger($app['webauthn.log']);
})
);
$this->app->bind(
AuthenticatorAssertionResponseValidator::class,
fn ($app) => tap(new AuthenticatorAssertionResponseValidator(
$app[PublicKeyCredentialSourceRepository::class],

Check failure on line 210 in src/WebauthnServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan (8.2)

Fetching class constant class of deprecated class Webauthn\PublicKeyCredentialSourceRepository.
null,
$app[ExtensionOutputCheckerHandler::class],
$app[CoseAlgorithmManager::class]
), function ($responseValidator) use ($app) {
$responseValidator->setCounterChecker($app[CounterChecker::class])
->setLogger($app['log']);
->setLogger($app['webauthn.log']);
})
);
$this->app->bind(
Expand Down Expand Up @@ -242,7 +242,7 @@
fn ($app) => tap(new PublicKeyCredentialLoader(
$app[AttestationObjectLoader::class]
), function ($loader) use ($app) {
$loader->setLogger($app['log']);
$loader->setLogger($app['webauthn.log']);
})
);

Expand Down Expand Up @@ -292,7 +292,7 @@
return Psr18ClientDiscovery::find();
// @codeCoverageIgnoreStart
} catch (NotFoundException $e) {
Log::error('Could not find PSR-18 Client Factory.', ['exception' => $e]);
app('webauthn.log')->error('Could not find PSR-18 Client Factory.', ['exception' => $e]);
throw new BindingResolutionException('Unable to resolve PSR-18 Client Factory. Please install a psr/http-client-implementation implementation like \'guzzlehttp/guzzle\'.');
}
}
Expand All @@ -307,7 +307,7 @@
return Psr17FactoryDiscovery::findRequestFactory();
// @codeCoverageIgnoreStart
} catch (NotFoundException $e) {
Log::error('Could not find PSR-17 Request Factory.', ['exception' => $e]);
app('webauthn.log')->error('Could not find PSR-17 Request Factory.', ['exception' => $e]);
throw new BindingResolutionException('Unable to resolve PSR-17 Request Factory. Please install psr/http-factory-implementation implementation like \'guzzlehttp/psr7\'.');
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@
return new PsrHttpFactory($serverRequestFactory, $streamFactory, $uploadFileFactory, $responseFactory);
// @codeCoverageIgnoreStart
} catch (NotFoundException $e) {
Log::error('Could not find PSR-17 Factory.', ['exception' => $e]);
app('webauthn.log')->error('Could not find PSR-17 Factory.', ['exception' => $e]);
}
}

Expand Down
Loading