So I Have a Authorization handler as such:
public class StationToIDMMatchHandler : IAuthorizationHandler
{
private readonly IHttpContextAccessor _httpContextAccessor = null;
private readonly AftermarketDbContext _db;
public StationToIDMMatchHandler(IHttpContextAccessor httpContextAccessor, AftermarketDbContext db)
{
_httpContextAccessor = httpContextAccessor;
_db = db;
}
public Task HandleAsync(AuthorizationHandlerContext context)
{
HttpContext httpContext = _httpContextAccessor.HttpContext; // Access context here
string StationUniqueId = httpContext.Request.Headers.Where(x => x.Key == " StationUniqueId").FirstOrDefault().Value;
var listOfRoles = context.User.Claims.Where(c => c.Type == "groups").Select(x => x.Value).ToList();
string requiredIDMRole = _db.StationRole.Where(DbStationUniqueId => DbStationUniqueId.StationId == StationUniqueId).ToString();
if (listOfRoles.Contains(requiredIDMRole))
{
context.Succeed();
return Task.CompletedTask;
}
else
return Task.CompletedTask;
}
}
}
But I don't have any requirement other than the ones I already checked that I want to return. And I can't use a context.Succeed();without a parameter.
How do I do this? Must I really create a empty class that implements IAuthorizationRequrement to send in? This does not seem like a good way to do it.