-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cs
More file actions
54 lines (48 loc) · 2.14 KB
/
Copy pathTest.cs
File metadata and controls
54 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using WebAuthn_Client_.NET.Cryptographic;
namespace WebAuthn_Client_.NET
{
public class Test
{
public static void RunExample()
{
var authenticator = new FIDOWebAuthn();
// Registration example
var createOptions = new PublicKeyCredentialCreationOptions
{
Rp = new RelyingParty { Id = "example.com", Name = "Example Corp" },
User = new User
{
Id = Base64UrlHelper.EncodeString("user123"),
Name = "john.doe@example.com",
DisplayName = "John Doe"
},
Challenge = Base64UrlHelper.EncodeString("random-challenge-123"),
PubKeyCredParams = new List<PublicKeyCredentialParameters>
{
new PublicKeyCredentialParameters { Alg = -7 }, // ES256
new PublicKeyCredentialParameters { Alg = -257 } // RS256
},
Attestation = "none"
};
var credential = authenticator.Create(createOptions);
Console.WriteLine($"Created credential: {credential.Id}");
// Verify the attestation object can be decoded
var attestationObjectBytes = Base64UrlHelper.Decode(
((AuthenticatorAttestationResponse)credential.Response).AttestationObject);
var decodedAttestation = CborHelper.DecodeAttestationObject(attestationObjectBytes);
Console.WriteLine($"Attestation format: {decodedAttestation["fmt"]}");
// Authentication example
var getOptions = new PublicKeyCredentialRequestOptions
{
Challenge = Base64UrlHelper.EncodeString("auth-challenge-456"),
RpId = "example.com",
AllowCredentials = new List<PublicKeyCredentialDescriptor>
{
new PublicKeyCredentialDescriptor { Id = credential.Id }
}
};
var assertion = authenticator.Get(getOptions);
Console.WriteLine($"Authentication successful for credential: {assertion.Id}");
}
}
}