blazor-workshop icon indicating copy to clipboard operation
blazor-workshop copied to clipboard

Authentication Error

Open smcniel24 opened this issue 4 years ago • 5 comments

Need a little help. As I'm following through the tutorial and testing the first time the ability to Register or Login in I'm not getting the buttons to register or login option. It's going straight to the display of "..." which is classified as Authorizing from the LoginDisplay.razor page..

@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager

<div class="user-info">
    <AuthorizeView>
        <Authorizing>
            <text>...</text>
        </Authorizing>
        <Authorized>
            <img src="img/user.svg" />
            <div>
                <a href="authentication/profile" class="username">@context.User.Identity.Name</a>
                <button class="btn btn-link sign-out" @onclick="BeginSignOut">Sign out</button>
            </div>
        </Authorized>
        <NotAuthorized>
            <a class="sign-in" href="authentication/register">Register</a>
            <a class="sign-in" href="authentication/login">Log in</a>
        </NotAuthorized>
    </AuthorizeView>
</div>

I have this in my Main function in the Programs page and it compiles and runs but goes straight to <Authorizing> instead of <NotAuthorized>.

builder.Services.AddApiAuthorization();

When I replace the above code with the following code I found in newer releases of the source code I can't run it because the top line throws me an error. (AddRemoteAuthentication)

 builder.Services.AddRemoteAuthentication<PizzaAuthenticationState, ApiAuthorizationProviderOptions>();
            builder.Services.AddApiAuthorization(options =>
            {
                options.AuthenticationPaths.LogOutSucceededPath = "";
                options.ProviderOptions.ConfigurationEndpoint = "_configuration/BlazingPizza.Client"; // temporary workaround
            });

I believe, but don't know for sure, that this may be the culprit of my error.

Thanks. Scott

smcniel24 avatar Apr 23 '20 22:04 smcniel24

Hi, if you're just studying the first 5 chapters.

In the program.cs code, you can refer to the following code

 public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("app");

            builder.Services.AddBaseAddressHttpClient();

            builder.Services.AddScoped<OrderState>();


            // Add auth services
            builder.Services.AddApiAuthorization();

            await builder.Build().RunAsync();
        }
    }

ltm0203 avatar Apr 24 '20 06:04 ltm0203

If you created the template yourself, all the pages under this path must exist.

https://github.com/dotnet-presentations/blazor-workshop/tree/master/src/BlazingPizza.Server/Areas/Identity/Pages

ltm0203 avatar Apr 24 '20 06:04 ltm0203

I am having a problem at the same step in the tutorial. In my case I am getting an unhandled error: Failed to load resource: the server responded with a status of 404 () crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component. Could not load settings from '_configuration/BlazingPizza.Client' at Function.createUserManager (https://localhost44381/_content/Microsoft.AspNetCore.Components.WebAssembly.Authentican/AuthenticationService.js:1:5893)

image

gclee46 avatar Jun 06 '20 00:06 gclee46

As I started the BlazingPizza project completely from scratch and in 06-authentication-and-authorization I received the same error as gclee46 commented on Jun 6.

In my case in the BlazingPizza.Server project the OidcConfigurationController was missing.

public class OidcConfigurationController : Controller { public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider) { ClientRequestParametersProvider = clientRequestParametersProvider; }

    public IClientRequestParametersProvider ClientRequestParametersProvider { get; }

    [HttpGet("_configuration/{clientId}")]
    public IActionResult GetClientRequestParameters([FromRoute]string clientId)
    {
        var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId);
        return Ok(parameters);
    }
}

bartvanhoey avatar Jul 28 '20 20:07 bartvanhoey