Skip to content

Commit 8ac3524

Browse files
committed
Remove base-class
1 parent df37692 commit 8ac3524

File tree

13 files changed

+18
-68
lines changed

13 files changed

+18
-68
lines changed

BlazorWasmDemo/Client/Shared/UserService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ public async Task<string> LoginAsync(string? username)
134134
return "No options received";
135135
}
136136

137-
if (options.Status != "ok")
138-
{
139-
return options.ErrorMessage ?? string.Empty;
140-
}
141-
142137
// Present options to user and get response (usernameless users will be asked by their authenticator, which credential they want to use to sign the challenge)
143138
var assertion = await _webAuthn.VerifyAsync(options);
144139

BlazorWasmDemo/Server/Controllers/UserController.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public CredentialCreateOptions GetCredentialOptions(
126126
// 6. return options to client
127127
return options;
128128
}
129-
catch (Exception e)
129+
catch (Exception)
130130
{
131-
return new CredentialCreateOptions { Status = "error", ErrorMessage = FormatException(e) };
131+
throw;
132132
}
133133
}
134134

@@ -152,11 +152,6 @@ public async Task<string> CreateCredentialAsync([FromRoute] string username, [Fr
152152
// 3. Verify and make the credentials
153153
var result = await _fido2.MakeNewCredentialAsync(attestationResponse, options, CredentialIdUniqueToUserAsync, cancellationToken: cancellationToken);
154154

155-
if (result.Status is "error" || result.Result is null)
156-
{
157-
return result.ErrorMessage ?? string.Empty;
158-
}
159-
160155
// 4. Store the credentials in db
161156
_demoStorage.AddCredentialToUser(options.User, new StoredCredential
162157
{
@@ -229,9 +224,9 @@ public AssertionOptions MakeAssertionOptions([FromRoute] string? username, [From
229224
// 5. return options to client
230225
return options;
231226
}
232-
catch (Exception e)
227+
catch (Exception)
233228
{
234-
return new AssertionOptions { Status = "error", ErrorMessage = FormatException(e) };
229+
throw;
235230
}
236231
}
237232

@@ -281,18 +276,12 @@ public async Task<string> MakeAssertionAsync([FromBody] AuthenticatorAssertionRa
281276
cancellationToken: cancellationToken);
282277

283278
// 4. Store the updated counter
284-
if (res.Status is "ok")
285-
{
286-
_demoStorage.UpdateCounter(res.CredentialId, res.SignCount);
287-
if (res.DevicePublicKey is not null)
288-
{
289-
creds.DevicePublicKeys.Add(res.DevicePublicKey);
290-
}
291-
}
292-
else
279+
_demoStorage.UpdateCounter(res.CredentialId, res.SignCount);
280+
if (res.DevicePublicKey is not null)
293281
{
294-
return $"Error: {res.ErrorMessage}";
282+
creds.DevicePublicKeys.Add(res.DevicePublicKey);
295283
}
284+
296285

297286
// 5. return result to client
298287
var handler = new JwtSecurityTokenHandler();

Demo/Controller.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public JsonResult MakeCredentialOptions([FromForm] string username,
8181
}
8282
catch (Exception e)
8383
{
84-
return Json(new CredentialCreateOptions { Status = "error", ErrorMessage = FormatException(e) });
84+
return Json(new { Status = "error", ErrorMessage = FormatException(e) });
8585
}
8686
}
8787

@@ -132,7 +132,7 @@ public async Task<JsonResult> MakeCredential([FromBody] AuthenticatorAttestation
132132
}
133133
catch (Exception e)
134134
{
135-
return Json(new MakeNewCredentialResult(status: "error", errorMessage: FormatException(e), result: null));
135+
return Json(new { status = "error", errorMessage = FormatException(e)});
136136
}
137137
}
138138

@@ -177,7 +177,7 @@ public ActionResult AssertionOptionsPost([FromForm] string username, [FromForm]
177177

178178
catch (Exception e)
179179
{
180-
return Json(new AssertionOptions { Status = "error", ErrorMessage = FormatException(e) });
180+
return Json(new { Status = "error", ErrorMessage = FormatException(e) });
181181
}
182182
}
183183

@@ -218,7 +218,7 @@ public async Task<JsonResult> MakeAssertion([FromBody] AuthenticatorAssertionRaw
218218
}
219219
catch (Exception e)
220220
{
221-
return Json(new VerifyAssertionResult { Status = "error", ErrorMessage = FormatException(e) });
221+
return Json(new { Status = "error", ErrorMessage = FormatException(e) });
222222
}
223223
}
224224
}

Src/Fido2.Models/AssertionOptions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Fido2NetLib;
99
/// <summary>
1010
/// Sent to the browser when we want to Assert credentials and authenticate a user
1111
/// </summary>
12-
public class AssertionOptions : Fido2ResponseBase
12+
public class AssertionOptions
1313
{
1414
/// <summary>
1515
/// This member represents a challenge that the selected authenticator signs, along with other data, when producing an authentication assertion.
@@ -71,8 +71,6 @@ public static AssertionOptions Create(
7171
{
7272
return new AssertionOptions()
7373
{
74-
Status = "ok",
75-
ErrorMessage = string.Empty,
7674
Challenge = challenge,
7775
Timeout = config.Timeout,
7876
RpId = config.ServerDomain,

Src/Fido2.Models/CredentialCreateOptions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Fido2NetLib;
88

9-
public sealed class CredentialCreateOptions : Fido2ResponseBase
9+
public sealed class CredentialCreateOptions
1010
{
1111
/// <summary>
1212
///
@@ -117,8 +117,6 @@ public static CredentialCreateOptions Create(
117117
{
118118
return new CredentialCreateOptions
119119
{
120-
Status = "ok",
121-
ErrorMessage = string.Empty,
122120
Challenge = challenge,
123121
Rp = new PublicKeyCredentialRpEntity(config.ServerDomain, config.ServerName, config.ServerIcon),
124122
Timeout = config.Timeout,

Src/Fido2.Models/Fido2ResponseBase.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

Src/Fido2.Models/Objects/MakeNewCredentialResult.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@ namespace Fido2NetLib.Objects;
55
/// <summary>
66
/// Result of parsing and verifying attestation. Used to transport Public Key back to RP.
77
/// </summary>
8-
public sealed class MakeNewCredentialResult : Fido2ResponseBase
8+
public sealed class MakeNewCredentialResult(RegisteredPublicKeyCredential result)
99
{
10-
public MakeNewCredentialResult(string status, string errorMessage, RegisteredPublicKeyCredential? result)
11-
{
12-
Status = status;
13-
ErrorMessage = errorMessage;
14-
Result = result;
15-
}
16-
17-
public RegisteredPublicKeyCredential? Result { get; }
10+
public RegisteredPublicKeyCredential Result { get; } = result;
1811

1912
// todo: add debuginfo?
2013
}

Src/Fido2.Models/Objects/RegisteredPublicKeyCredential.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Fido2NetLib.Objects;
55
/// <summary>
66
/// Holds parsed credential data
77
/// </summary>
8-
public class RegisteredPublicKeyCredential : Fido2ResponseBase
8+
public class RegisteredPublicKeyCredential
99
{
1010
/// <summary>
1111
/// The type of the public key credential source.

Src/Fido2.Models/Objects/VerifyAssertionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Result of the MakeAssertion verification
55
/// </summary>
6-
public class VerifyAssertionResult : Fido2ResponseBase
6+
public class VerifyAssertionResult
77
{
88
public byte[] CredentialId { get; init; }
99

Src/Fido2/AuthenticatorAssertionResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ public async Task<VerifyAssertionResult> VerifyAsync(
176176

177177
return new VerifyAssertionResult
178178
{
179-
Status = "ok",
180179
CredentialId = Raw.Id,
181180
SignCount = authData.SignCount,
182181
IsBackedUp = authData.IsBackedUp,

0 commit comments

Comments
 (0)