-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hi David,
I have a .NetFramework 4.7 WebApi project. I had added the Microsoft.Owin.Security.Authorization.WebApi Nuget package.
In my StartUp,cs I have the following line
app.UseAuthorization(o =>
{
o.AddPolicy("contribute", policy => policy.RequireClaim(JwtClaimTypes.Role, "User.Contributor"));
});
In my controller I have added
[HttpGet]
[Route("{cargoShipmentGBID}/parties")]
[ResourceAuthorize(Policy = "contribute")]
[SwaggerResponse(HttpStatusCode.OK)]
[SwaggerResponse(HttpStatusCode.BadRequest,"Bad request")]
[SwaggerResponse(HttpStatusCode.NotFound,"Could not find a booking based on the ID")]
[SwaggerOperation(OperationId = "Get Booking Parties")]
public async Task RetrievePartyDetails(int cargoShipmentGBID)
However I end up with the following exception
{
"Message": "An error has occurred.",
"ExceptionMessage": "One or more errors occurred.",
"ExceptionType": "System.AggregateException",
"StackTrace": " at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)\r\n at System.Threading.Tasks.Task1.get_Result()\r\n at Microsoft.Owin.Security.Authorization.WebApi.ResourceAuthorizeAttribute.IsAuthorized(HttpActionContext actionContext)\r\n at System.Web.Http.AuthorizeAttribute.OnAuthorization(HttpActionContext actionContext)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Value cannot be null.\r\nParameter name: context",
"ExceptionType": "System.ArgumentNullException",
"StackTrace": " at Microsoft.Owin.Security.Authorization.OwinContextExtensions.GetAuthorizationOptions(IOwinContext context)\r\n at Microsoft.Owin.Security.Authorization.AuthorizationHelper.d__2.MoveNext()"
}
}
Do you have any idea?
Thanks,