Microsoft.AspNetCore.SignalR.AuthorizeAttribute.AuthorizeHubMethodInvocation C# (CSharp) Method

AuthorizeHubMethodInvocation() public method

Determines whether client is authorized to invoke the IHub method.
public AuthorizeHubMethodInvocation ( IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod ) : bool
hubIncomingInvokerContext IHubIncomingInvokerContext An providing details regarding the method invocation.
appliesToMethod bool Indicates whether the interface instance is an attribute applied directly to a method.
return bool
        public virtual bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            if (hubIncomingInvokerContext == null)
            {
                throw new ArgumentNullException("hubIncomingInvokerContext");
            }

            // It is impossible to require outgoing auth at the method level with SignalR's current design.
            // Even though this isn't the stage at which outgoing auth would be applied, we want to throw a runtime error
            // to indicate when the attribute is being used with obviously incorrect expectations.

            // We must explicitly check if _requireOutgoing is true since it is a Nullable type.
            if (appliesToMethod && (_requireOutgoing == true))
            {
                throw new ArgumentException(Resources.Error_MethodLevelOutgoingAuthorization);
            }

            return UserAuthorized(hubIncomingInvokerContext.Hub.Context.User);
        }