Authorize attribute for SignalR using OWIN Application Cookies

I wanted to authenticate my SignalR connections using my OWIN application cookie. I couldn’t find any way to do this so here is the attribute I had to make. Is this necessary? If not, please let me know…

public class AuthorizeWithOwinApplicationCookieAttribute : AuthorizeAttribute
{
    public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
    {
        var owinContext = request.GetHttpContext().GetOwinContext();
        SignInManager<AppUser, Guid> signInManager = owinContext.Get<ApplicationSignInManager>();
        var result = signInManager.AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.ApplicationCookie).WaitAndUnwrapException();
        if (result == null)
            return false;

        request.Environment["server.User"] = new ClaimsPrincipal(result.Identity);
        return true;
    }

    public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
    {
        var connectionId = hubIncomingInvokerContext.Hub.Context.ConnectionId;
        // check the authenticated user principal from environment
        var environment = hubIncomingInvokerContext.Hub.Context.Request.Environment;
        var principal = environment["server.User"] as ClaimsPrincipal;
        if (principal != null && principal.Identity != null && principal.Identity.IsAuthenticated)
        {
            // create a new HubCallerContext instance with the principal generated from token
            // and replace the current context so that in hubs we can retrieve current user identity
            hubIncomingInvokerContext.Hub.Context = new HubCallerContext(new ServerRequest(environment), connectionId);
            return true;
        }
        else
        {
            return false;
        }
    }
}