Skip to content

Commit e449abd

Browse files
committed
feat: add a no auth mode for socketio
1 parent d07cf76 commit e449abd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ S3_SECRET_KEY=minioadmin
2323
# POSTGRES=postgres://user:pass@localhost/database
2424
# POSTGRES_TESTDB=yredis_tests ## use a different database for testing
2525

26+
### Skip authentication
27+
## Only works in SocketIO mode
28+
# NO_AUTH=true
29+
2630
### Auth signature
2731
## The auth server authenticates web clients using json-web-tokens (jwt).
2832
## They are generated and validated using the following json-web-keys (jwk).

src/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import * as promise from 'lib0/promise'
1010
import { Server } from 'socket.io'
1111
import { registerYSocketIOServer } from './socketio.js'
1212
import http from 'http'
13+
import { randomUUID } from 'crypto'
14+
15+
const skipAuth = env.getConf('no-auth') === 'true'
1316

1417
const wsServerPublicKey = await ecdsa.importKeyJwk(
1518
json.parse(env.ensureConf('auth-public-key'))
@@ -117,6 +120,7 @@ export const createYSocketIOServer = async ({
117120
const server = await registerYSocketIOServer(io, store, {
118121
redisPrefix,
119122
authenticate: async (socket) => {
123+
if (skipAuth) return { userid: randomUUID().toString() }
120124
const token = socket.handshake.query.yauth
121125
if (!token) return null
122126
// verify that the user has a valid token

0 commit comments

Comments
 (0)