File: artifacts\obj\IdentitySample.PasskeyUI\Release\net11.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components\Pages\Home_razor.g.cs
Project: src\src\Identity\samples\IdentitySample.PasskeyUI\IdentitySample.PasskeyUI.csproj (IdentitySample.PasskeyUI)
#pragma checksum "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor" "{8829d00f-11b8-4213-878b-770e8597ac16}" "1174ea82ba84006ff95e67c428124ece5aeddd72d9d73a88c73dfafacdfc65c6"
// <auto-generated/>
#pragma warning disable 1591
namespace IdentitySample.PasskeyUI.Components.Pages
{
    #line default
    using global::System;
    using global::System.Collections.Generic;
    using global::System.Linq;
    using global::System.Threading.Tasks;
    using global::Microsoft.AspNetCore.Components;
#nullable restore
#line (1,2)-(1,23) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using System.Net.Http
 
#nullable disable
    ;
#nullable restore
#line (2,2)-(2,28) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using System.Net.Http.Json
 
#nullable disable
    ;
#nullable restore
#line (3,2)-(3,53) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.AspNetCore.Components.Authorization
 
#nullable disable
    ;
#nullable restore
#line (4,2)-(4,45) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.AspNetCore.Components.Forms
 
#nullable disable
    ;
#nullable restore
#line (5,2)-(5,47) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.AspNetCore.Components.Routing
 
#nullable disable
    ;
#nullable restore
#line (6,2)-(6,43) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.AspNetCore.Components.Web
 
#nullable disable
    ;
#nullable restore
#line (7,2)-(7,61) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using static Microsoft.AspNetCore.Components.Web.RenderMode
 
#nullable disable
    ;
#nullable restore
#line (8,2)-(8,58) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.AspNetCore.Components.Web.Virtualization
 
#nullable disable
    ;
#nullable restore
#line (9,2)-(9,27) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\_Imports.razor"
using Microsoft.JSInterop
 
#nullable disable
    ;
#nullable restore
#line (3,2)-(3,43) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
using Microsoft.AspNetCore.Authentication
 
#nullable disable
    ;
#nullable restore
#line (4,2)-(4,37) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
using Microsoft.AspNetCore.Identity
 
#nullable disable
    ;
#nullable restore
#line (5,2)-(5,42) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
using Microsoft.AspNetCore.Identity.Test
 
#nullable disable
    ;
    #line default
    #line hidden
    [global::Microsoft.AspNetCore.Components.RouteAttribute(
    // language=Route,Component
#nullable restore
#line (1,7)-(1,10) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
"/"
 
#line default
#line hidden
#nullable disable
    )]
    #nullable restore
    public partial class Home : global::Microsoft.AspNetCore.Components.ComponentBase
    #nullable disable
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
            __builder.AddMarkupContent(0, "<h1>Welcome!</h1>\r\n\r\n");
            __builder.OpenComponent<global::Microsoft.AspNetCore.Components.Web.PageTitle>(1);
            __builder.AddAttribute(2, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
                __builder2.AddContent(3, "Passkey sample");
            }
            ));
            __builder.CloseComponent();
            __builder.AddMarkupContent(4, "\r\n\r\n");
            __builder.AddMarkupContent(5, "<p>\r\n    This app demonstrates how to use passkeys for authentication with ASP.NET Core Identity.\r\n</p>\r\n\r\n");
            __builder.AddMarkupContent(6, "<p>\r\n    See <a href=\"https://learn.microsoft.com/microsoft-edge/devtools-guide-chromium/webauthn/\" target=\"_blank\">these docs</a>\r\n    to learn how to simplify passkey testing with a virtual authenticator.\r\n</p>\r\n\r\n");
            __builder.AddMarkupContent(7, "<p><b>NOTE:</b> For simplicity, users are stored in memory, so passkeys will be lost when the app restarts.\r\n</p>\r\n\r\n");
            __builder.AddMarkupContent(8, "<h3>Log in or register here</h3>\r\n\r\n");
            __builder.OpenElement(9, "form");
            __builder.AddAttribute(10, "id", "auth-form");
            __builder.AddAttribute(11, "method", "post");
            string __formName = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<string>("auth");
            __builder.AddAttribute(12, "onsubmit", global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::System.EventArgs>(this, 
#nullable restore
#line (30,64)-(30,77) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
OnSubmitAsync
 
#line default
#line hidden
#nullable disable
            ));
            __builder.AddNamedEvent("onsubmit", __formName);
            __builder.OpenComponent<global::Microsoft.AspNetCore.Components.Forms.AntiforgeryToken>(13);
            __builder.CloseComponent();
            __builder.AddMarkupContent(14, "\r\n    ");
            __builder.AddMarkupContent(15, "<div><input type=\"text\" id=\"input-username\" name=\"username\" placeholder=\"Username\" autocomplete=\"username webauthn\"></div>\r\n    ");
            __builder.AddMarkupContent(16, "<div><button type=\"submit\" name=\"action\" value=\"register\" id=\"input-register\">Register</button>\r\n        <button type=\"submit\" name=\"action\" value=\"authenticate\" id=\"input-authenticate\">Authenticate</button></div>");
            __builder.CloseElement();
            __builder.AddMarkupContent(17, "\r\n\r\n");
            __builder.OpenElement(18, "p");
            __builder.AddAttribute(19, "id", "status-message");
#nullable restore
#line (41,25)-(41,38) 25 "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
__builder.AddContent(20, statusMessage
 
#line default
#line hidden
#nullable disable
            );
            __builder.CloseElement();
        }
        #pragma warning restore 1998
#nullable restore
#line (43,8)-(131,1) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
 
    private string? statusMessage;
 
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;
 
    [SupplyParameterFromForm(Name = "username")]
    private string? Username { get; set; }
 
    [SupplyParameterFromForm(Name = "credential")]
    private string? CredentialJson { get; set; }
 
    [SupplyParameterFromForm(Name = "action")]
    private string? Action { get; set; }
 
    private Task OnSubmitAsync()
        => Action switch
        {
            "register" => RegisterAsync(),
            "authenticate" => AuthenticateAsync(),
            var x => throw new InvalidOperationException($"Unknown action '{x}'"),
        };
 
    private async Task RegisterAsync()
    {
        if (string.IsNullOrWhiteSpace(Username))
        {
            statusMessage = "Error: A username is required for registration.";
            return;
        }
 
        if (string.IsNullOrWhiteSpace(CredentialJson))
        {
            statusMessage = "Error: No credential was submitted by the browser.";
            return;
        }
 
        var attestationResult = await SignInManager.PerformPasskeyAttestationAsync(CredentialJson);
        if (!attestationResult.Succeeded)
        {
            statusMessage = $"Error: Could not validate credential: {attestationResult.Failure.Message}";
            return;
        }
 
        // Create the user if they don't exist yet.
        var userEntity = attestationResult.UserEntity;
        var user = await UserManager.FindByIdAsync(userEntity.Id);
        if (user is null)
        {
            user = new PocoUser(userName: userEntity.Name)
            {
                Id = userEntity.Id,
            };
            var createUserResult = await UserManager.CreateAsync(user);
            if (!createUserResult.Succeeded)
            {
                statusMessage = "Error: Could not create a new user.";
                return;
            }
        }
 
        var setPasskeyResult = await UserManager.AddOrUpdatePasskeyAsync(user, attestationResult.Passkey);
        if (!setPasskeyResult.Succeeded)
        {
            statusMessage = "Error: Could not update the user with the new passkey.";
            return;
        }
 
        statusMessage = "Registration successful! You can now authenticate with your passkey.";
    }
 
    private async Task AuthenticateAsync()
    {
        if (string.IsNullOrWhiteSpace(CredentialJson))
        {
            statusMessage = "Error: No credential was submitted by the browser.";
            return;
        }
 
        var signInResult = await SignInManager.PasskeySignInAsync(CredentialJson);
        if (!signInResult.Succeeded)
        {
            statusMessage = "Error: Could not sign in with the provided credential.";
            return;
        }
 
        NavigationManager.NavigateTo("authenticated", forceLoad: true);
    }
 
#line default
#line hidden
#nullable disable
 
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private 
#nullable restore
#line (9,9)-(9,30) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
UserManager<PocoUser>
 
#line default
#line hidden
#nullable disable
         
#nullable restore
#line (9,31)-(9,42) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
UserManager
 
#line default
#line hidden
#nullable disable
         { get; set; }
         = default!;
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private 
#nullable restore
#line (8,9)-(8,32) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
SignInManager<PocoUser>
 
#line default
#line hidden
#nullable disable
         
#nullable restore
#line (8,33)-(8,46) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
SignInManager
 
#line default
#line hidden
#nullable disable
         { get; set; }
         = default!;
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private 
#nullable restore
#line (7,9)-(7,26) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
NavigationManager
 
#line default
#line hidden
#nullable disable
         
#nullable restore
#line (7,27)-(7,44) "D:\a\_work\1\s\src\Identity\samples\IdentitySample.PasskeyUI\Components\Pages\Home.razor"
NavigationManager
 
#line default
#line hidden
#nullable disable
         { get; set; }
         = default!;
    }
}
#pragma warning restore 1591