generated from Firehed/php-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add latest fields to Credential object (#17)
This updates Credential to the latest API spec, including defining a new `enum` to cover the transports.
- Loading branch information
Showing
8 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SnapAuth\WebAuthn; | ||
|
||
/** | ||
* @link https://www.w3.org/TR/webauthn-3/#enum-transport | ||
*/ | ||
enum AuthenticatorTransport: string | ||
{ | ||
/** | ||
* Bluetooth Low Energy | ||
*/ | ||
case Ble = 'ble'; | ||
|
||
/** | ||
* Smart Cards | ||
*/ | ||
case SmartCard = 'smart-card'; | ||
|
||
/** | ||
* Mixed transport methods, including (but not limited to) Cross-Device | ||
* Authentication | ||
*/ | ||
case Hybrid = 'hybrid'; | ||
|
||
/** | ||
* Platform authenticators, such as system-managed credential managers | ||
*/ | ||
case Internal = 'internal'; | ||
|
||
/** | ||
* Near-Field Communication | ||
*/ | ||
case Nfc = 'nfc'; | ||
|
||
/** | ||
* Removable USB devices | ||
*/ | ||
case Usb = 'usb'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Web Authentication enums | ||
|
||
The enumerations in this directory are direct representations of those from the WebAuthn spec. | ||
|
||
See https://www.w3.org/TR/webauthn-3/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SnapAuth; | ||
|
||
use DateTimeImmutable; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function assert; | ||
use function file_get_contents; | ||
use function is_array; | ||
use function json_decode; | ||
use function sprintf; | ||
|
||
use const JSON_THROW_ON_ERROR; | ||
|
||
#[CoversClass(Credential::class)] | ||
#[Small] | ||
class CredentialTest extends TestCase | ||
{ | ||
public function testDecodingFromApiResponse(): void | ||
{ | ||
$data = $this->readFixture('credential1.json'); | ||
$cred = new Credential($data); | ||
|
||
self::assertSame('ctl_2893f2Vg86463c8xV7wVv5PG', $cred->id); | ||
self::assertSame('fbfc3007-154e-4ecc-8c0b-6e020557d7bd', $cred->aaguid); | ||
self::assertTrue($cred->isActive); | ||
self::assertTrue($cred->isBackedUp); | ||
self::assertTrue($cred->isBackupEligible); | ||
self::assertTrue($cred->isUvInitialized); | ||
self::assertSame('iCloud Keychain', $cred->name); | ||
self::assertSame([ | ||
WebAuthn\AuthenticatorTransport::Hybrid, | ||
WebAuthn\AuthenticatorTransport::Internal, | ||
], $cred->transports); | ||
self::assertEquals(new DateTimeImmutable('2024-03-07T20:02:04Z'), $cred->createdAt); | ||
} | ||
|
||
public function testDecodingUsbFromApiResponse(): void | ||
{ | ||
$data = $this->readFixture('credential2.json'); | ||
$cred = new Credential($data); | ||
|
||
self::assertSame('ctl_28CWCw4G3R4MGCg2cc2ccvGr', $cred->id); | ||
self::assertSame('00000000-0000-0000-0000-000000000000', $cred->aaguid); | ||
self::assertTrue($cred->isActive); | ||
self::assertFalse($cred->isBackedUp); | ||
self::assertFalse($cred->isBackupEligible); | ||
self::assertFalse($cred->isUvInitialized); | ||
self::assertSame('Passkey', $cred->name); | ||
self::assertSame([WebAuthn\AuthenticatorTransport::Usb], $cred->transports); | ||
self::assertEquals(new DateTimeImmutable('2024-08-05T21:35:48Z'), $cred->createdAt); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
private function readFixture(string $path): array | ||
{ | ||
$path = sprintf('%s/%s/%s', __DIR__, 'fixtures', $path); | ||
$json = file_get_contents($path); | ||
assert($json !== false); | ||
$data = json_decode($json, true, flags: JSON_THROW_ON_ERROR); | ||
assert(is_array($data)); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "ctl_2893f2Vg86463c8xV7wVv5PG", | ||
"aaguid": "fbfc3007-154e-4ecc-8c0b-6e020557d7bd", | ||
"isActive": true, | ||
"isBackedUp": true, | ||
"isBackupEligible": true, | ||
"isUvInitialized": true, | ||
"name": "iCloud Keychain", | ||
"transports": [ | ||
"hybrid", | ||
"unknown_ignoreme", | ||
"internal" | ||
], | ||
"createdAt": 1709841724 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": "ctl_28CWCw4G3R4MGCg2cc2ccvGr", | ||
"aaguid": "00000000-0000-0000-0000-000000000000", | ||
"isActive": true, | ||
"isBackedUp": false, | ||
"isBackupEligible": false, | ||
"isUvInitialized": false, | ||
"name": "Passkey", | ||
"transports": [ | ||
"usb" | ||
], | ||
"createdAt": 1722893748 | ||
} |