Search code examples
c#thinktecture

Thinktecture ResourcAuthorization, no AuthorizationManager set


I am trying to build a sample web application using the Thinktecture sample ResourceAuthorization from github.

Now I have an action in the controller decorated with authorize attribute:

[ResourceAuthorize("Edit", "Resource")]
    public ActionResult Edit()
    {
        return View();
    }

I implemented my own AuthorizationManager:

 public class AuthorizationManager : ResourceAuthorizationManager
{
    public override Task<bool> CheckAccessAsync(ResourceAuthorizationContext context)
    {
        var resource = context.Resource.First().Value;

        if (resource == "Resources")
        {
            return CheckResourcesAccessAsync(context);
        }
        else
        {
            return Nok();
        }
    }

When I try to run my application now I keep getting the error:

No AuthorizationManager set.

I thought maybe I have to register the manager in the web.config like this:

 <system.identityModel>
<identityConfiguration>
    <claimsAuthenticationManager type="Namespace.xy.AuthorizationManager, Namespace.xy" />
</identityConfiguration>
</system.identityModel>

It doesn't work. What am I doing wrong?


Solution

  • The solution was to register the authorizationmanager in the startup:

     app.UseResourceAuthorization(new MyAuthorizationManager());