HangfireIO / HangfireIO/Hangfire
async Authorize for IDashboardAuthorizationFilter
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
I'm currently integrating Hangfire into an ASP.NET Core 1.1 application, and am implementing an `IDashboardAuthorizationFilter` to integrate with the Identity framework.
Here is my current implementation:
public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter {
private string policyName;
public HangfireAuthorizationFilter(string policyName) {
this.policyName = policyName;
}
public bool Authorize([NotNull] DashboardContext context) {
var httpContext = context.GetHttpContext();
var authService = httpContext.RequestServices.GetRequiredService();
return authService.AuthorizeAsync(httpContext.User, this.policyName).GetAwaiter().GetResult();
}
}
Unfortunately, all async methods need to be wrapped in `.GetAwaiter().GetResult()`, since there is no async version of `Authorize`. This can cause problems when integrating with services that only provide async methods, leading to potential deadlocks.
Are there any plans to implement an `AuthorizeAsync` on the `IDashboardAuthorizationFilter`?
Contributor guide
Research direction
Start from the IDashboardAuthorizationFilter interface and the shown Authorize implementation, then trace how dashboard authorization is invoked. Define completion as supporting asynchronous authorization for services that cannot be called safely through GetAwaiter().GetResult(), while preserving the dashboard filter behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- authorization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100