Commit graph

12 commits

Author SHA1 Message Date
Aarol D'Souza
5bb1dffab5
fix!: use secret for auth. between servers (#36778)
* fix: use secret for auth. between servers

* fix(security): use redis for server auth.

* fix: use socket.io directly to fetch secret from redis

* refactor: Socket secret can be bench specific

- No need to keep it site specific.

* fix: don't return anything if secrets dont match

* test: rewrite test to factor in server-to-server communication only

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2026-02-17 11:55:00 +05:30
Akhil Narang
7ddff768a8
fix(socketio): allow authorization header without cookies (#34199)
Resolves #34125

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-09-30 11:54:23 +05:30
Nikhil Kothari
85a40ee939 chore: linting 2024-06-21 17:26:16 +05:30
Nikhil Kothari
525f5b7131
fix(socketio): pass auth token if available instead of cookie 2024-06-14 19:52:43 +05:30
Ankush Menat
266b2797aa refactor: use Fetch API instead of superagent 2024-04-06 21:26:45 +05:30
Ankush Menat
b7f2073380 feat: Extensible SocketIO
You can now specify custom event handlers for SocketIO.

Usage:

1. In your app's hooks.py add `has_realtime_event_handlers=True` so
Framework can assume your app contains custom handler and import them.
2. Create a file called `/app/realtime/handlers.js` with single module
   export a function that will setup handlers using socket.

Here's sample code:

```js
// This is /app_root/realtime/handler.js`

function chat_app_handlers(socket) {
    socket.on("hello_chat") {
	console.log("hello world!");
    }
}

module.exports = chat_app_handlers;
```

3. Restart SocketIO server and see if it worked by sending event from
   client. In desk based app you can do
   `frappe.realtime.socket.emit("hello_chat")`

Middlewares are not yet possible... will be worked upon __some other day__ [tm]

closes https://github.com/frappe/frappe/issues/21528
2024-04-06 18:17:27 +05:30
Ankush Menat
a35e6b4975 fix: ignore if no cookies are sent 2024-02-12 14:19:58 +05:30
Ankush Menat
11ea7e4179 feat: socketio using authorization headers
Earlier socketio only worked in browser where browser would send cookie
(cause same domain) and hence socketio server used it to auth
connection.

This however is limited and doesn't allow simply creating socket
connection from apps.

Authorization headers on other hand are simple to implement.
2024-02-11 16:16:34 +05:30
Ankush Menat
be8d2b9de0 perf: lazy websocket connection on website
Establishing 1 connection for every website visit is too much.

Only after calling frappe.realtime.on(...) for ANY event, we will
establish a websocket connection.

This is used for handful of things:
- Discussion component
- File upload

Socketio was initially added here: https://github.com/frappe/frappe/pull/6866 this use case no longer exists.

Rarely anywhere website uses realtime.
2023-07-01 12:43:53 +05:30
Ankush Menat
bdaed29ef2 refactor: move handlers to separate file 2023-07-01 12:43:47 +05:30
Ankush Menat
d59e499418 refactor!: Use SocketIO namespaces for multitenancy 2023-07-01 10:53:34 +05:30
Ankush Menat
7320d2d020 refactor: move middleware out 2023-07-01 10:53:34 +05:30