From 8d96ef88929a3a9696f46845fd51dac72726d00f Mon Sep 17 00:00:00 2001 From: Deniz <59655898+dkadiog@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:48:42 +0100 Subject: [PATCH] feat: lookup auth header if token is not present in handshake If a middleware sets the token for the request, its not present in the handshake and therefore not authorized. This supports also a auth header. --- src/authorize.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/authorize.ts b/src/authorize.ts index 196cebe..fb956c7 100644 --- a/src/authorize.ts +++ b/src/authorize.ts @@ -42,6 +42,9 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => { return async (socket, next) => { let encodedToken: string | null = null const { token } = socket.handshake.auth + if (token == null) { + token = socket.handshake.headers.authorization + } if (token != null) { const tokenSplitted = token.split(' ') if (tokenSplitted.length !== 2 || tokenSplitted[0] !== 'Bearer') {