socket-controllers icon indicating copy to clipboard operation
socket-controllers copied to clipboard

feat: add @Authorized() decorator

Open acuntex opened this issue 7 years ago • 10 comments

Is there any chance to create an Authorized-Decorator like in routing controllers?

Would be nice, if you could limit the connections to only authorized users (directly at connect or at message-level) and to inject the user.

acuntex avatar Jan 10 '18 10:01 acuntex

Hi @acuntex!

I am not familiar with the project and I don't think pleerock will have any free time soon to work on this project. However, the community can pick this up and implement and document it then it can be merged.

The first step would be to actually discuss your proposal. How do you expect the @Authorized decorator to work? The first message must include an authorization message or every message should contain the authorization payload?

NoNameProvided avatar Nov 04 '18 17:11 NoNameProvided

Any news or workarounds? I'm trying to the same thing - protect some of my socket.io "routes".

fr3fou avatar Feb 24 '19 14:02 fr3fou

@fr3fou maybe we do it, also you can use middlewares.

rustamwin avatar Feb 25 '19 07:02 rustamwin

Do you have an example of the thing I'm trying to accomplish - authentication with socket.io. I'm using passport.js, routing-controllers, socket-controllers and socket.io. Right now for some reason calling req.isAuthenticated() gives me false for some reason.

fr3fou avatar Feb 25 '19 07:02 fr3fou

See sample5

@Middleware()
export class AuthenticationMiddleware implements MiddlewareInterface {

    use(socket: any, next: ((err?: any) => any)): any { // where socketio instance. not connected socket instance!
        console.log("authentication..."); // your auth logic here
        next();
    }

}

rustamwin avatar Feb 25 '19 07:02 rustamwin

How would I use the middleware only for specific routes, not all?

fr3fou avatar Feb 25 '19 08:02 fr3fou

What did you mean "routes"? events?

rustamwin avatar Feb 25 '19 10:02 rustamwin

if yes, it is problem

rustamwin avatar Feb 25 '19 10:02 rustamwin

Events / messages

fr3fou avatar Feb 25 '19 10:02 fr3fou

For events no, because the middlewares works globally. As I said before it is problem

rustamwin avatar Feb 25 '19 10:02 rustamwin

You can implement your own auth solution using interceptors per event, or use the middleware per connection.

attilaorosz avatar Apr 11 '23 17:04 attilaorosz

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar May 12 '23 01:05 github-actions[bot]