Skip to content

Commit 331b5f6

Browse files
committed
PR feedback
1 parent d178068 commit 331b5f6

File tree

6 files changed

+42
-40
lines changed

6 files changed

+42
-40
lines changed

src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<IsTrimmable>true</IsTrimmable>
1111
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
1212
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
13-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1413
</PropertyGroup>
1514

1615
<ItemGroup>

src/Identity/Core/src/Passkeys/BufferSource.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public override int GetHashCode()
122122
/// <summary>
123123
/// Gets the UTF-8 string representation of the byte buffer.
124124
/// </summary>
125-
public override unsafe string ToString()
125+
public override string ToString()
126126
{
127127
var span = _bytes.Span;
128128

@@ -131,9 +131,6 @@ public override unsafe string ToString()
131131
return string.Empty;
132132
}
133133

134-
fixed (byte* ptr = span)
135-
{
136-
return Encoding.UTF8.GetString(ptr, span.Length);
137-
}
134+
return Encoding.UTF8.GetString(span);
138135
}
139136
}

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public static IEndpointConventionBuilder MapAdditionalIdentityEndpoints(this IEn
7171
accountGroup.MapPost("/PasskeyRequestOptions", async (
7272
[FromServices] UserManager<ApplicationUser> userManager,
7373
[FromServices] SignInManager<ApplicationUser> signInManager,
74-
[FromQuery] string? email) =>
74+
[FromQuery] string? username) =>
7575
{
76-
var user = string.IsNullOrEmpty(email) ? null : await userManager.FindByEmailAsync(email);
76+
var user = string.IsNullOrEmpty(username) ? null : await userManager.FindByNameAsync(username);
7777
var passkeyRequestArgs = new PasskeyRequestArgs<ApplicationUser>
7878
{
7979
User = user,

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/wwwroot/BlazorWeb-CSharp.lib.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function createCredential() {
2121
}
2222

2323
async function requestCredential(email) {
24-
const optionsResponse = await fetchWithErrorHandling(`/Account/PasskeyRequestOptions?email=${email}`, {
24+
const optionsResponse = await fetchWithErrorHandling(`/Account/PasskeyRequestOptions?username=${email}`, {
2525
method: 'POST',
2626
});
2727
const optionsJson = await optionsResponse.json();

src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorTemplateTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ await Task.WhenAll(
136136
await IncrementCounterAsync(page);
137137
}
138138

139-
if (authenticationFeatures.HasFlag(AuthenticationFeatures.Basic))
139+
if (authenticationFeatures.HasFlag(AuthenticationFeatures.RegisterAndLogIn))
140140
{
141141
await Task.WhenAll(
142142
page.WaitForURLAsync("**/Account/Login**", new() { WaitUntil = WaitUntilState.NetworkIdle }),
@@ -214,7 +214,7 @@ await Task.WhenAll(
214214
await page.ClickAsync("text=Add a new passkey");
215215

216216
await page.WaitForSelectorAsync("text=Enter a name for your passkey");
217-
await page.FillAsync("[name=\"RenameInput.DisplayName\"]", "My passkey");
217+
await page.FillAsync("[name=\"Input.Name\"]", "My passkey");
218218
await page.ClickAsync("text=Continue");
219219

220220
await page.WaitForSelectorAsync("text=Passkey updated successfully");
@@ -300,7 +300,7 @@ protected enum BlazorTemplatePages
300300
protected enum AuthenticationFeatures
301301
{
302302
None = 0,
303-
Basic = 1,
303+
RegisterAndLogIn = 1,
304304
Passkeys = 2,
305305
}
306306
}

src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorWebTemplateTest.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Net;
5-
using System.Net.Http;
6-
using System.Net.Http.Headers;
75
using Microsoft.AspNetCore.BrowserTesting;
8-
using Microsoft.AspNetCore.InternalTesting;
96
using Templates.Test.Helpers;
107

118
namespace BlazorTemplates.Tests;
@@ -20,8 +17,7 @@ public class BlazorWebTemplateTest(ProjectFactoryFixture projectFactory) : Blazo
2017
[InlineData(BrowserKind.Chromium, "WebAssembly")]
2118
[InlineData(BrowserKind.Chromium, "Auto")]
2219
[InlineData(BrowserKind.Chromium, "None", "Individual")]
23-
[InlineData(BrowserKind.Chromium, "None", "Individual", true)]
24-
public async Task BlazorWebTemplate_Works(BrowserKind browserKind, string interactivityOption, string authOption = "None", bool testPasskeys = false)
20+
public async Task BlazorWebTemplate_Works(BrowserKind browserKind, string interactivityOption, string authOption = "None")
2521
{
2622
var project = await CreateBuildPublishAsync(
2723
args: ["-int", interactivityOption, "-au", authOption],
@@ -32,16 +28,42 @@ public async Task BlazorWebTemplate_Works(BrowserKind browserKind, string intera
3228
? BlazorTemplatePages.Counter
3329
: BlazorTemplatePages.None;
3430

35-
var authenticationFeatures = AuthenticationFeatures.None;
36-
if (authOption is not "None")
37-
{
38-
authenticationFeatures |= AuthenticationFeatures.Basic;
39-
}
40-
if (testPasskeys)
31+
var authenticationFeatures = authOption is "None"
32+
? AuthenticationFeatures.None
33+
: AuthenticationFeatures.RegisterAndLogIn;
34+
35+
await TestProjectCoreAsync(project, browserKind, pagesToExclude, authenticationFeatures);
36+
37+
bool HasClientProject()
38+
=> interactivityOption is "WebAssembly" or "Auto";
39+
40+
Project GetTargetProject(Project rootProject)
4141
{
42-
authenticationFeatures |= AuthenticationFeatures.Passkeys;
42+
if (HasClientProject())
43+
{
44+
// Multiple projects were created, so we need to specifically select the server
45+
// project to be used
46+
return GetSubProject(rootProject, rootProject.ProjectName, rootProject.ProjectName);
47+
}
48+
49+
// In other cases, just use the root project
50+
return rootProject;
4351
}
52+
}
53+
54+
[Theory]
55+
[InlineData(BrowserKind.Chromium)]
56+
public async Task BlazorWebTemplate_CanUsePasskeys(BrowserKind browserKind)
57+
{
58+
var project = await CreateBuildPublishAsync(args: ["-int", "None", "-au", "Individual"]);
59+
var pagesToExclude = BlazorTemplatePages.Counter;
60+
var authenticationFeatures = AuthenticationFeatures.RegisterAndLogIn | AuthenticationFeatures.Passkeys;
61+
62+
await TestProjectCoreAsync(project, browserKind, pagesToExclude, authenticationFeatures);
63+
}
4464

65+
private async Task TestProjectCoreAsync(Project project, BrowserKind browserKind, BlazorTemplatePages pagesToExclude, AuthenticationFeatures authenticationFeatures)
66+
{
4567
var appName = project.ProjectName;
4668

4769
// Test the built project
@@ -65,21 +87,5 @@ public async Task BlazorWebTemplate_Works(BrowserKind browserKind, string intera
6587
await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");
6688
await TestBasicInteractionInNewPageAsync(browserKind, aspNetProcess.ListeningUri.AbsoluteUri, appName, pagesToExclude, authenticationFeatures);
6789
}
68-
69-
bool HasClientProject()
70-
=> interactivityOption is "WebAssembly" or "Auto";
71-
72-
Project GetTargetProject(Project rootProject)
73-
{
74-
if (HasClientProject())
75-
{
76-
// Multiple projects were created, so we need to specifically select the server
77-
// project to be used
78-
return GetSubProject(rootProject, rootProject.ProjectName, rootProject.ProjectName);
79-
}
80-
81-
// In other cases, just use the root project
82-
return rootProject;
83-
}
8490
}
8591
}

0 commit comments

Comments
 (0)