Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication Error #238

Open
smcniel24 opened this issue Apr 23, 2020 · 5 comments
Open

Authentication Error #238

smcniel24 opened this issue Apr 23, 2020 · 5 comments

Comments

@smcniel24
Copy link

smcniel24 commented Apr 23, 2020

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 instead of .

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

@ltm0203
Copy link

ltm0203 commented Apr 24, 2020

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
Copy link

ltm0203 commented Apr 24, 2020

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

@gclee46
Copy link

gclee46 commented Jun 6, 2020

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

@bartvanhoey
Copy link

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);
    }
}

@onionware-github
Copy link

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 instead of .

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

I had the same issue, I only get "..." instead of a login control. I added this attribute to the OrderContext class in the BlazingPizza.Shared project:
[JsonSerializable(typeof(Dictionary<string, string>))]

Now it works for me.

EdCharbeneau added a commit to EdCharbeneau/blazor-workshop that referenced this issue Sep 20, 2023
@EdCharbeneau EdCharbeneau mentioned this issue Sep 21, 2023
csharpfritz pushed a commit that referenced this issue Nov 29, 2023

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
* Shared lib updated with Nullable context. Partially fixes issue #105.

* Server updated with Nullable context. Partially fixes issue #105.

* Razor projects updated with Nullable context. Partially fixes issue #105.

* 01 updated with Nullable context, including instructions (md). Partially fixes issue #105.

* Updated 02. Dependencies to use Nullable

* Updated code to include nullable considerations.

* Updated instructions to align with nullable.

* Updated dependencies to use nullable context

* Fixes issue #358 and Fixes issue #238

* Sync with previous lesson

* Removed guard on GetUserId to allow workshop to flow without authorization.

* Sync changes across lessons

* Updated 03 with nullability context

* Updated instructions with nullable code

* Cleanup whitespace

* Sync dependencies 04 with previous steps

* Fixed: Starting point 04's server code was actually from a later step 06 or above.

* Sync 04 client changes with previous steps

* Updated client with nullable context enabled

* Sync dependencies 05 with previous changes

* Fixed step 05 controller is from step 06

* Sync with client with previous step

* Updated 05 with nullable context enabled

* Sync with previous steps

* Updated 06 with nullable context enabled.

* Synced dependencies with previous lesson

* Sync client changes with previous step

* Updated 07 with nullable context enabled

* Synced dependencies with previous step

* Synced client with previous lesson

* Updated 08 with nullable conetext enabled

* Sync with prevous lesson

* Updated 09 with nullable context enabled

* Updated src with nullable context enabled

* Updated docs

* Notification interop doesn't work with required.

* Extra sln file

* Fixed link that moved for getting started

* Removed extra comments.

* Clairified the message about EditorRequired.

* Trimmed whitespace

* Supressed nullable warning on change event

* Added EditorRequired to step

* Refactored GetUserId. This code was duplicated in multiple places.

* Updated `!=` to `is not` null

* Fixes: SignoutSessionStateManager obsolete warning. See: https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/7.0/wasm-app-authentication

* Added Nullable to orderWithStatus

* Updated Razor Class Library verbage, it was reminicent of .NET Core 3.0/3.1

* Changed `!=` to `is not null`

* The app was updated to include a Minimal API implementation of NotificationsController. However the code in save-point/09 and instructions were not updated. This fixes the issue.

* Pulling up some missed changes from the final exercise

* Removed unused NavigationManager references

* Updated code on Map component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants