Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Problem with authorization through policy's/requirements #860

Closed
@mythjuha

Description

@mythjuha

Almost certainly i'm doing something wrong, but i've been searching for days with no luck.

In my project, i'm using custom implementations of userstore, passworsstore, etc ... . And a custom class as "User".

services.AddScoped<IUserStore<Person>, AuthenticationService>();
services.AddScoped<IUserPasswordStore<Person>, AuthenticationService>();
services.AddScoped<IUserEmailStore<Person>, AuthenticationService>();
services.AddScoped<IUserRoleStore<Person>, AuthenticationService>();
services.AddScoped<IUserPhoneNumberStore<Person>, AuthenticationService>();
services.AddScoped<IUserLockoutStore<Person>, AuthenticationService>();
services.AddScoped<IRoleStore<LoginRole>, AuthenticationService>();

services.AddIdentity<Person, LoginRole>(o =>
             .AddDefaultTokenProviders();

services.AddAuthorization((options) => 
{
options.AddPolicy("PolicyName", policy =>
            {
                policy.AddRequirements(new Authorization.SomeRequirement(sp.GetService<UserManager<Person>>()));
                policy.RequireAuthenticatedUser();
            });
);

In a API controller that has the policy as authorization, the code is executed and succees. However, my logs show me the following message:

Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware: Information: HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Identity.Application.
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware: Information: AuthenticationScheme: Identity.Application was successfully authenticated.
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService: Information: Authorization failed for user: my_username.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Warning: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
Microsoft.AspNetCore.Mvc.ChallengeResult: Information: Executing ChallengeResult with authentication schemes (Identity.Application).
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware: Information: AuthenticationScheme: Identity.Application was forbidden.

What is the DefaultAuthorizationService and why is it being called?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions