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

Policies #59

Open
Schoof-T opened this issue Jan 22, 2024 · 0 comments
Open

Policies #59

Schoof-T opened this issue Jan 22, 2024 · 0 comments

Comments

@Schoof-T
Copy link

Schoof-T commented Jan 22, 2024

I'm trying to add Policy authorization to my project, but I can't seem to get it to work.

I have the following policy:

    public static class Policies
    {
        public const string Viewer = "Viewer";

        public static AuthorizationPolicy CanViewPolicy(string securityGroup)
        {
            return new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .RequireClaim("SecurityRole", securityGroup)
                .Build();
        }
     }

In the server project I added:

    services.AddAuthorization(authorizationOptions =>
    {
        authorizationOptions.FallbackPolicy = authorizationOptions.DefaultPolicy;
        authorizationOptions.AddPolicy(Policies.Viewer, Policies.CanViewPolicy("TEST"));
    });

In the client project I added:

            builder.Services.AddAuthorizationCore(config =>
            {
                config.FallbackPolicy = config.DefaultPolicy;
                config.AddPolicy(Policies.Viewer, policy => policy.Requirements.Add(new ViewerRequirement("TEST"));
            });

My user has the claim "TEST" when I check in the HostAuthenticationStateProvider.
But I still can't access pages that have @attribute [Authorize(Policy = Policies.Viewer)]

Any ideas?

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

1 participant