Skip to content

Commit

Permalink
Fix to encode/decode credential id as base64url (#631)
Browse files Browse the repository at this point in the history
* Fix to encode/decode credential id as base64url

---------

Co-authored-by: Florent Morselli <florent.morselli@spomky-labs.com>
  • Loading branch information
abcang and Spomky authored Jul 16, 2024
1 parent 0c8246c commit 47b20e6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/webauthn/src/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webauthn;

use InvalidArgumentException;
use ParagonIE\ConstantTime\Base64UrlSafe;

/**
* @see https://w3c.github.io/webappsec-credential-management/#credential
Expand Down Expand Up @@ -33,10 +34,10 @@ public function __construct(
'The property "$id" is deprecated and will be removed in 5.0.0. Please set null use "rawId" instead.'
);
} else {
$id = base64_encode($rawId);
$id = Base64UrlSafe::encodeUnpadded($rawId);
}
$this->id = $id;
$this->rawId = $rawId ?? base64_encode($id);
$this->rawId = $rawId ?? Base64UrlSafe::decodeNoPadding($id);
}

/**
Expand Down

0 comments on commit 47b20e6

Please sign in to comment.