|
3 | 3 | using System.IdentityModel.Tokens.Jwt; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Net.Http; |
| 6 | +using System.Net.Http.Json; |
6 | 7 | using System.Security.Cryptography; |
7 | 8 | using System.Security.Cryptography.X509Certificates; |
8 | 9 | using System.Text; |
9 | 10 | using System.Text.Json; |
| 11 | +using System.Text.Json.Serialization; |
10 | 12 | using System.Threading; |
11 | 13 | using System.Threading.Tasks; |
| 14 | + |
| 15 | +using Fido2NetLib.Internal; |
| 16 | +using Fido2NetLib.Serialization; |
| 17 | + |
12 | 18 | using Microsoft.IdentityModel.Tokens; |
13 | 19 |
|
14 | 20 | namespace Fido2NetLib |
@@ -48,15 +54,16 @@ public ConformanceMetadataRepository(HttpClient? client, string origin) |
48 | 54 |
|
49 | 55 | public async Task<MetadataBLOBPayload> GetBLOBAsync(CancellationToken cancellationToken = default) |
50 | 56 | { |
51 | | - var req = new |
| 57 | + var req = new GetBLOBRequest(_origin); |
| 58 | + |
| 59 | + var content = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(req, FidoSerializerContext.Default.GetBLOBRequest)) |
52 | 60 | { |
53 | | - endpoint = _origin |
| 61 | + Headers = { { "Content-Type", "application/json" } } |
54 | 62 | }; |
55 | 63 |
|
56 | | - var content = new StringContent(JsonSerializer.Serialize(req), Encoding.UTF8, "application/json"); |
57 | 64 | using var response = await _httpClient.PostAsync(_getEndpointsUrl, content, cancellationToken); |
58 | 65 | await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken); |
59 | | - var result = await JsonSerializer.DeserializeAsync<MDSGetEndpointResponse>(responseStream, cancellationToken: cancellationToken); |
| 66 | + MDSGetEndpointResponse? result = await JsonSerializer.DeserializeAsync(responseStream, FidoSerializerContext.Default.MDSGetEndpointResponse, cancellationToken: cancellationToken); |
60 | 67 | var conformanceEndpoints = result!.Result; |
61 | 68 |
|
62 | 69 | var combinedBlob = new MetadataBLOBPayload |
@@ -231,7 +238,7 @@ public async Task<MetadataBLOBPayload> DeserializeAndValidateBlob(string rawBLOB |
231 | 238 |
|
232 | 239 | var blobPayload = ((JwtSecurityToken)validatedToken).Payload.SerializeToJson(); |
233 | 240 |
|
234 | | - var blob = JsonSerializer.Deserialize<MetadataBLOBPayload>(blobPayload)!; |
| 241 | + MetadataBLOBPayload blob = JsonSerializer.Deserialize(blobPayload, FidoModelSerializerContext.Default.MetadataBLOBPayload)!; |
235 | 242 | blob.JwtAlg = blobAlg; |
236 | 243 | return blob; |
237 | 244 | } |
|
0 commit comments