Skip to content

Blazor Server authorization fails with Microsoft.AspNetCore.Authentication.Negotiate  #17527

@akorchev

Description

@akorchev

Describe the bug

It seems that the Authorize attribute does not work with Microsoft.AspNetCore.Authentication.Negotiate authentication and roles.

To Reproduce

  1. Create a server-side blazor application with Windows Authentication.
  2. Add the Microsoft.AspNetCore.Authentication.Negotiate package.
  3. Enable it
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
  1. Use middleware to challenge the authentication scheme:
 services.AddScoped<ValidateAuthentication>();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseMiddleware<ValidateAuthentication>();
    internal class ValidateAuthentication : IMiddleware
    {
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            if (context.User.Identity.IsAuthenticated)
                await next(context);
            else
                await context.ChallengeAsync();
        }
    }
  1. Add authorize attribute to Index.razor with some group that your windows user is a member of.
@attribute [Authorize(Policy = "TestGroup")]
  1. Important !!! Run with the default profile from launch settings and not IIS Express!!! (it works with IIS Express). After logging in the app would show you that you are not authorized even though you are a member of the group.
    image

Strangely enough if you debug IsInRole("TestGroup") returns true.
image

I suspect it is related to the authentication scheme which one normally could pass to the Authorize attribute. However Blazor doesn't allow setting the AuthenticationSchemes property of the Authorize attribute:

NotSupportedException: The authorization data specifies an authentication scheme. Authentication schemes cannot be specified for components.
Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.EnsureNoAuthenticationSchemeSpecified(IAuthorizeData[] authorizeData)

Further technical details

  • ASP.NET Core version: 3.1.100-preview3-014645
  • Visual Studio 2019 Preview 6, Windows 10 Pro

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authIncludes: Authn, Authz, OAuth, OIDC, Bearer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions