-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Closed
Copy link
Labels
area-authIncludes: Authn, Authz, OAuth, OIDC, BearerIncludes: Authn, Authz, OAuth, OIDC, Bearer
Description
Describe the bug
It seems that the Authorize attribute does not work with Microsoft.AspNetCore.Authentication.Negotiate authentication and roles.
To Reproduce
- Create a server-side blazor application with Windows Authentication.
- Add the Microsoft.AspNetCore.Authentication.Negotiate package.
- Enable it
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
- 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();
}
}
- Add authorize attribute to Index.razor with some group that your windows user is a member of.
@attribute [Authorize(Policy = "TestGroup")]
- 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.

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

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
Labels
area-authIncludes: Authn, Authz, OAuth, OIDC, BearerIncludes: Authn, Authz, OAuth, OIDC, Bearer