title: Authorize Attribute with Roles not working?
body: <p>I am trying to get this working, but no luck so far.  My Authorize attribute works on its own, but once i state a Role that the user must be apart of, then i get the following message returned from my webapi</p>
  
  <pre><code>{"message":"Authorization has been denied for this request."}
  </code></pre>
  
  <p>Startup.cs</p>
  
  <pre><code>public void Configuration(IAppBuilder app)
  {
      //HttpConfiguration config = new HttpConfiguration();
  
      ConfigureOAuth(app);
  
      // simple injector
      SimpleInjectorConfig.Register();
  
      AutoMapperConfig.RegisterMappings();
      AreaRegistration.RegisterAllAreas();
      GlobalConfiguration.Configure(WebApiConfig.Register);
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
  
      app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
  }
  
  public void ConfigureOAuth(IAppBuilder app)
  {
      OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
      {
          AllowInsecureHttp = true,
          TokenEndpointPath = new PathString("/token"),
          AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
          Provider = new SimpleAuthorizationServerProvider(new AccountService(new DataContext()))
      };
  
      // Token Generation
      app.UseOAuthAuthorizationServer(OAuthServerOptions);
      app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  
  }
  </code></pre>
  
  <p>SimpleAuthorizationServerProvider.cs</p>
  
  <pre><code>public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
  {
      private AccountService _service;
  
      public SimpleAuthorizationServerProvider(AccountService service)
      {
          _service = service;
      }
  
      public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
      {
          context.Validated();
      }
  
  
      public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
      {
  
          context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
  
          User user = await _service.FindUserAsync(context.UserName, context.Password);
  
          if (user == null)
          {
              context.SetError("invalid_grant", "The user name or password is incorrect.");
              return;
          }
  
  
          var identity = new ClaimsIdentity(context.Options.AuthenticationType);
          identity.AddClaim(new Claim("sub", context.UserName));
          //identity.AddClaim(new Claim("role", "user"));
  
          context.Validated(identity);
  
      }
  }
  </code></pre>
  
  <p>Decorating a controller method, i use</p>
  
  <pre><code>[Authorize(Roles="CanViewCompany")]
  </code></pre>
  
  <p>If i use just this, it works and returns the data i would expect</p>
  
  <pre><code>[Authorize]
  </code></pre>
  
  <p>My basic User class</p>
  
  <pre><code>public class User : IdentityUser&lt;long, UserLogin, UserRole, UserClaim&gt;, IUser&lt;long&gt;
  {
      public User()
          : base()
      {
          this.Groups = new HashSet&lt;UserGroup&gt;();
      }
  
      public virtual ICollection&lt;UserGroup&gt; Groups { get; set; }
  
  }
  </code></pre>
  
  <p>I am sure i am missing something, but i just aint sure what.  Any help much appreciated</p>