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

Add Custom extractor which takes JwtFromRequestFunction as argument #235

Open
Abdelwahab313 opened this issue Jun 14, 2022 · 1 comment
Open

Comments

@Abdelwahab313
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.

I think we needed a way to add custom extractor for jwt, as we are using passport for authenticating on third party webhook which sends the token inside nested field in body, another reason is to authenticate for websocket handshake as mentioned in this Issue.

So my approach is to use a custom extractor which takes JwtFromRequestFunction as argument.

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..392fa82 100644
--- a/node_modules/passport-jwt/lib/extract_jwt.js
+++ b/node_modules/passport-jwt/lib/extract_jwt.js
@@ -71,6 +71,10 @@ extractors.fromAuthHeaderAsBearerToken = function () {
     return extractors.fromAuthHeaderWithScheme(BEARER_AUTH_SCHEME);
 };
 
+extractors.fromCustomExtractor = function (extractor_callback) {
+  return extractor_callback;
+};
+
 
 extractors.fromExtractors = function(extractors) {
     if (!Array.isArray(extractors)) {

This issue body was partially generated by patch-package.

@Outternet
Copy link

even though the patch library works conveniently, this functionality is already in the code. Just pass the callback directly to jwtFromRequest.

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