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

NotAuthroized Does Not Work With Windows Authentication Blazor 8 #53100

Open
1 task done
chobo2 opened this issue Jan 2, 2024 · 1 comment
Open
1 task done

NotAuthroized Does Not Work With Windows Authentication Blazor 8 #53100

chobo2 opened this issue Jan 2, 2024 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one
Milestone

Comments

@chobo2
Copy link

chobo2 commented Jan 2, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi

I am using Balzo 8 with Server / Per Page / Per Component and I cannot get the "NotAuthorized" tag to work.

Routes.razor

    @using Microsoft.AspNetCore.Components.Authorization
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
                <NotAuthorized>
                    Not Authroized
                </NotAuthorized>
            </AuthorizeRouteView>
            <FocusOnNavigate RouteData="@routeData" Selector="h1" />
        </Found>
    </Router>

Weather.razor

    @page "/weather"
    @using Microsoft.AspNetCore.Authorization
    @attribute [StreamRendering]
    @attribute [Authorize(Roles = "test")]
    <PageTitle>Weather</PageTitle>
    
    <h1>Weather</h1>
    
    <p>This component demonstrates showing data.</p>
    
    @if (forecasts == null)
    {
        <p><em>Loading...</em></p>
    }
    else
    {
        <table class="table">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Temp. (C)</th>
                    <th>Temp. (F)</th>
                    <th>Summary</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var forecast in forecasts)
                {
                    <tr>
                        <td>@forecast.Date.ToShortDateString()</td>
                        <td>@forecast.TemperatureC</td>
                        <td>@forecast.TemperatureF</td>
                        <td>@forecast.Summary</td>
                    </tr>
                }
            </tbody>
        </table>
    }
    
    @code {
        private WeatherForecast[]? forecasts;
    
        protected override async Task OnInitializedAsync()
        {
            // Simulate asynchronous loading to demonstrate streaming rendering
            await Task.Delay(500);
    
            var startDate = DateOnly.FromDateTime(DateTime.Now);
            var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
            forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = startDate.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = summaries[Random.Shared.Next(summaries.Length)]
            }).ToArray();
        }
    
        private class WeatherForecast
        {
            public DateOnly Date { get; set; }
            public int TemperatureC { get; set; }
            public string? Summary { get; set; }
            public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
        }
    }

Program.cs

using BlazorApp11.Components;
 using Microsoft.AspNetCore.Authentication.Negotiate;
 
 namespace BlazorApp11
 {
 	public class Program
 	{
 		public static void Main(string[] args)
 		{
 			var builder = WebApplication.CreateBuilder(args);
 
 			// Add services to the container.
 			builder.Services.AddRazorComponents()
 				.AddInteractiveServerComponents();
 
 			builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme);
 
 			builder.Services.AddAuthorization(options =>
 			{
 				options.FallbackPolicy = options.DefaultPolicy;
 			});
 
 			builder.Services.AddCascadingAuthenticationState();
 
 			var app = builder.Build();
 
 			// Configure the HTTP request pipeline.
 			if (!app.Environment.IsDevelopment())
 			{
 				app.UseExceptionHandler("/Error");
 				// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
 				app.UseHsts();
 			}
 
 			app.UseHttpsRedirection();
 
 			app.UseStaticFiles();
 			app.UseAntiforgery();
 
 			app.MapRazorComponents<App>()
 				.AddInteractiveServerRenderMode();
 
 			app.Run();
 		}
 	}
 }

Am I missing something? When I go to the Weather Page, I get 403 Forbidden with none of my layout. I was expecting to see "Not Authorized"

I created a Blazor 6 application with the Windows Authentication template and compared, but I am not sure what I am missing.

I also see when I use the Individual Identity it has the "NotAuthorized" and it seems to work.

Expected Behavior

To see my message I written in the NotAuthorized Tag.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

Net 8

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jan 2, 2024
@chobo2
Copy link
Author

chobo2 commented Jan 11, 2024

There's a new docs issue on this subject at: dotnet/AspNetCore.Docs#31402

There are at least a couple of PU issues that seem related to this ...

For this specific concern over NotAuthorized content failing to appear, I'm looking at Javier's comment ...

During [static] SSR we won't show NotAuthorized, because your component doesn't even get to render.

I added [static] because I think the remark means 'not interactive'.

UPDATE: The full investigation at #52176 lists the other related issues that devs have opened.

Hi

So this is a known issue? I looked through the links you have but I am having trouble following along. Is there a solution to this?

I see if you change it from "Per Component" back to "Global" then everything works but I do want to stay with "Per Component".

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun labels Feb 6, 2024
@mkArtakMSFT mkArtakMSFT added this to the .NET 10 Planning milestone Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 10 Planning, Backlog Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

3 participants