Team XSockets.NET


The Authorize attribute can be used on controller/method level. When applied the method cant be called unless the connection has a IPrincipal set on the ConnectionContext. See the section about Authentication if you need info about setting the IPrincipal.

You can pass in specific role/users to the Authorize attribute if needed. When a call to a method with the Authorize attribute is made the OnAuthorization method is invoked. You can override that method if you want to do some custom logic. If the OnAuthorization method returns false the OnAuthorizationFailure method will be invoked. You can override that method as well.

using XSockets.Core.XSocket;
using XSockets.Core.XSocket.Helpers;
using XSockets.Core.Common.Socket.Attributes;
using XSockets.Plugin.Framework;
using System.Threading.Tasks;
using XSockets.Core.Common.Utility.Logging;
using XSockets.Core.Common.Socket.Event.Interface;

public class Sample : XSocketController
    public async Task Secure(IMessage m)
        await this.InvokeToAll(m);

    public override Task<bool> OnAuthorization(IAuthorizeAttribute authorizeAttribute)
        Composable.GetExport<IXLogger>().Information("OnAuthorization: {@a}", authorizeAttribute);
        return base.OnAuthorization(authorizeAttribute);

    public override Task OnAuthorizationFailure(string methodName)
        Composable.GetExport<IXLogger>().Information("OnAuthorizationFailure: {m}", methodName);
        return base.OnAuthorizationFailure(methodName);

results matching ""

    No results matching ""