Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passport-jwt extractor fromUrlQueryParameter don't handle handshake requests (websocket) #230

Open
HugoTrick opened this issue Oct 21, 2021 · 1 comment

Comments

@HugoTrick
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Passport-jwt extractor fromUrlQueryParameter don't handle handshake requests (websocket).
Here how i fixed it !

Here is the diff that solved my problem:

diff --git a/node_modules/passport-jwt/lib/extract_jwt.js b/node_modules/passport-jwt/lib/extract_jwt.js
index 7f112ab..31b3fc7 100644
--- a/node_modules/passport-jwt/lib/extract_jwt.js
+++ b/node_modules/passport-jwt/lib/extract_jwt.js
@@ -39,10 +39,17 @@ extractors.fromBodyField = function (field_name) {
 
 extractors.fromUrlQueryParameter = function (param_name) {
     return function (request) {
-        var token = null,
-            parsed_url = url.parse(request.url, true);
-        if (parsed_url.query && Object.prototype.hasOwnProperty.call(parsed_url.query, param_name)) {
-            token = parsed_url.query[param_name];
+        if (request.handshake) {
+            var token = null;
+            if (request.handshake.query && request.handshake.query.token) {
+                token = request.handshake.query.token;
+            }
+        } else {
+            var token = null,
+                parsed_url = url.parse(request.url, true);
+            if (parsed_url.query && Object.prototype.hasOwnProperty.call(parsed_url.query, param_name)) {
+                token = parsed_url.query[param_name];
+            }
         }
         return token;
     };

This issue body was partially generated by patch-package.

@Outternet
Copy link

the library expects an http req object. the rewrite avoids these depencies by adding more validation. Again this could have been implemented with a custom extractor instead of a patch, please consult the documentation on how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants