Authorization Handlers Fail to run with nullable resource
In Asp.Net Core 2, I have a handler with the following signature (the resource is a nullable type). The handler fails to run when a pass a null resource is passed into it. Im guessing this happens when you pass a null value for a ref type resource as well.
Handler Signature: internal class TreatyManagementGroupAccessRequirementHandler : AuthorizationHandler<TreatyManagementGroupAccessRequirement, int?>
Code calling handler: int? tmg = editModel.TreatyInformation.TreatyManagementGroupId;
// this code always fails and never runs the above Auth handler. var authResult = await _authorizationService.AuthorizeAsync(User, tmg, Policies.RequireEditPermission);
I ... oh, I don't think we've ever considered the resource would be null. @HaoK ?
My scenario is that I have to check if the user is assigned to the treaty management group. However, we don't require that they actually select a treaty management group, thus it could be a null id.
That's a behavior of the default base AuthenticationHandler<TReq, TResources> (it doesn't invoke your method if resources is null) just implement IAuthenticationHandler directly and then you have full control