Skip to content

Commit

Permalink
fix: fix base64 padding (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Apr 19, 2022
1 parent bf6c54a commit 6ce3783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Auth/EloquentWebAuthnProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function retrieveByCredentials(array $credentials)
{
if ($this->isSignedChallenge($credentials)) {
try {
$webauthnKey = (Webauthn::model())::where([
'credentialId' => Base64UrlSafe::encode(Base64::decode($credentials['id'])),
])->firstOrFail();
$webauthnKey = (Webauthn::model())::where('credentialId', Base64UrlSafe::encode(Base64::decode($credentials['id'])))
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded(Base64::decode($credentials['id'])))
->firstOrFail();

return $this->retrieveById($webauthnKey->user_id);
} catch (ModelNotFoundException $e) {
Expand Down
16 changes: 10 additions & 6 deletions src/Services/Webauthn/CredentialRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ public function getRegisteredKeys(User $user): array
*/
private function model(string $credentialId): WebauthnKey
{
return (Webauthn::model())::where(array_filter(
[
'user_id' => $this->guard()->guest() ? null : $this->guard()->id(),
'credentialId' => Base64UrlSafe::encode($credentialId),
]
))->firstOrFail();
return (Webauthn::model())::where(function ($query) {
if ($this->guard()->check()) {
$query->where('user_id', $this->guard()->id());
}
})
->where(function ($query) use ($credentialId) {
$query->where('credentialId', Base64UrlSafe::encode($credentialId))
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded($credentialId));
})
->firstOrFail();
}

/**
Expand Down

0 comments on commit 6ce3783

Please sign in to comment.