-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONData.cs
More file actions
206 lines (156 loc) · 6.33 KB
/
Copy pathJSONData.cs
File metadata and controls
206 lines (156 loc) · 6.33 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace WebAuthn_Client_.NET
{
public class PublicKeyCredentialCreationOptions
{
[JsonPropertyName("rp")]
public required RelyingParty Rp { get; set; }
[JsonPropertyName("user")]
public required User User { get; set; }
[JsonPropertyName("challenge")]
public required string Challenge { get; set; }
[JsonPropertyName("pubKeyCredParams")]
public required List<PublicKeyCredentialParameters> PubKeyCredParams { get; set; }
[JsonPropertyName("timeout")]
[JsonConverter(typeof(NullableUIntStringNumberConverter))]
public uint? Timeout { get; set; }
[JsonPropertyName("excludeCredentials")]
public List<PublicKeyCredentialDescriptor>? ExcludeCredentials { get; set; }
[JsonPropertyName("authenticatorSelection")]
public AuthenticatorSelectionCriteria? AuthenticatorSelection { get; set; }
[JsonPropertyName("attestation")]
public string Attestation { get; set; } = "none";
}
public class PublicKeyCredentialRequestOptions
{
[JsonPropertyName("challenge")]
public required string Challenge { get; set; }
[JsonPropertyName("timeout")]
[JsonConverter(typeof(NullableUIntStringNumberConverter))]
public uint? Timeout { get; set; }
[JsonPropertyName("rpId")]
public string? RpId { get; set; }
[JsonPropertyName("allowCredentials")]
public List<PublicKeyCredentialDescriptor>? AllowCredentials { get; set; }
[JsonPropertyName("userVerification")]
public string UserVerification { get; set; } = "preferred";
}
public class RelyingParty
{
[JsonPropertyName("id")]
public string? Id { get; set; }
[JsonPropertyName("name")]
public required string Name { get; set; }
}
public class User
{
[JsonPropertyName("id")]
public required string Id { get; set; }
[JsonPropertyName("name")]
public required string Name { get; set; }
[JsonPropertyName("displayName")]
public required string DisplayName { get; set; }
}
public class PublicKeyCredentialParameters
{
[JsonPropertyName("type")]
public string Type { get; set; } = "public-key";
[JsonPropertyName("alg")]
public int Alg { get; set; }
}
public class PublicKeyCredentialDescriptor
{
[JsonPropertyName("type")]
public string Type { get; set; } = "public-key";
[JsonPropertyName("id")]
public required string Id { get; set; }
[JsonPropertyName("transports")]
public List<string>? Transports { get; set; }
}
public class AuthenticatorSelectionCriteria
{
[JsonPropertyName("authenticatorAttachment")]
public string? AuthenticatorAttachment { get; set; }
[JsonPropertyName("requireResidentKey")]
public bool RequireResidentKey { get; set; } = false;
[JsonPropertyName("residentKey")]
public string? ResidentKey { get; set; }
[JsonPropertyName("userVerification")]
public string UserVerification { get; set; } = "preferred";
}
// Response structures
public class PublicKeyCredential
{
[JsonPropertyName("id")]
public required string Id { get; set; }
[JsonPropertyName("rawId")]
public required string RawId { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; } = "public-key";
[JsonPropertyName("response")]
public required object Response { get; set; }
[JsonPropertyName("authenticatorAttachment")]
public required string AuthenticatorAttachment { get; set; }
[JsonPropertyName("clientExtensionResults")]
public Dictionary<string, object> ClientExtensionResults { get; set; } = new Dictionary<string, object>();
}
public class AuthenticatorAttestationResponse
{
[JsonPropertyName("clientDataJSON")]
public required string ClientDataJSON { get; set; }
[JsonPropertyName("attestationObject")]
public required string AttestationObject { get; set; }
[JsonPropertyName("transports")]
public List<string> Transports { get; set; } = new List<string> { "internal", "hybrid" };
}
public class AuthenticatorAssertionResponse
{
[JsonPropertyName("clientDataJSON")]
public required string ClientDataJSON { get; set; }
[JsonPropertyName("authenticatorData")]
public required string AuthenticatorData { get; set; }
[JsonPropertyName("signature")]
public required string Signature { get; set; }
[JsonPropertyName("userHandle")]
public required string UserHandle { get; set; }
}
public class ClientData
{
[JsonPropertyName("type")]
public required string Type { get; set; }
[JsonPropertyName("challenge")]
public required string Challenge { get; set; }
[JsonPropertyName("origin")]
public required string Origin { get; set; }
[JsonPropertyName("crossOrigin")]
public bool CrossOrigin { get; set; } = false;
}
public sealed class NullableUIntStringNumberConverter : JsonConverter<uint?>
{
public override uint? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
return null;
if (reader.TokenType == JsonTokenType.Number)
return reader.GetUInt32();
if (reader.TokenType == JsonTokenType.String)
{
var value = reader.GetString();
if (string.IsNullOrWhiteSpace(value))
return null;
if (uint.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var result))
return result;
}
throw new JsonException("Expected timeout to be an unsigned integer or numeric string.");
}
public override void Write(Utf8JsonWriter writer, uint? value, JsonSerializerOptions options)
{
if (value.HasValue)
writer.WriteNumberValue(value.Value);
else
writer.WriteNullValue();
}
}
}