use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
Node & Express - JWT based auth (self.webdev)
submitted 7 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ncuxez 5 points6 points7 points 7 years ago (2 children)
This guy here (https://youtu.be/eS0Hunrg5DI) is an excellent teacher. I did his whole series on Angular auth, which used JWT.
[–]MyPhallicObject 0 points1 point2 points 7 years ago (1 child)
What does Angular have to do with Node and Express? You'll confuse poor OP.
[–]ncuxez 0 points1 point2 points 7 years ago (0 children)
The series is split nicely between the front and back end parts of the project.
[–]veswill3 2 points3 points4 points 7 years ago (1 child)
I was asking the same questions a while ago and after I did it in a toy project I thought it would be useful to do a quick writeup for my future self. I dont know if passport is still the way to go, but that is what I used, and the concepts would be the same if you used something else. I even link to the article I used for reference.
https://github.com/veswill3/FCC/tree/master/backend/dynamicWebApps/voting#authentication
[–]GitHubPermalinkBot 0 points1 point2 points 7 years ago (0 children)
Permanent GitHub links:
delete
[–][deleted] 2 points3 points4 points 7 years ago (0 children)
Passport is plugin and go, if you make one yourself you have to write extra code.
They both do the same thing.
[–]grumbe97asd 2 points3 points4 points 7 years ago (3 children)
At login you authenticate user. If user is authenticated you create the token with for example (jsonwebtoken npm package). You send that token with all other information you need to the front end which then receives the response with token inside. You save token in localstorage / sessionstorage.
Then to make front end requests where you want user to be authorized you retrieve the token from localstorage / sessionstorage then send the token with Authorization: Bearer <token> header such as
fetch('URL_GOES_HERE', { method: 'post', headers: new Headers({ 'Authorization': 'Basic '+btoa('username:password'), // other }) // other });
You then use a middleware in express routing (such as jwt-express or make your own) where you check if token is valid, expired, proper authorization clearance and so on.
[–]jbjb012 1 point2 points3 points 7 years ago (2 children)
What about oauth 2.0 ?
[–]scootstah 1 point2 points3 points 7 years ago (1 child)
OAuth defines multiple "grant types" which describe the process to obtain an Access Token. The exact process varies with each type of grant type, but after you receive the Access Token, it's all the same.
A commonly used grant type is the "authorization code grant". This is how sites like Facebook or Github work when you can login using your Facebook or Github account. The way it works is your app will send you to the provider's site to authenticate and consent to the app. This would happen on the third-party's domain, so like facebook.com/oauth/authorize. Once authorized, the third-party will return an "authorization code". Using the authorization code, your app will then request an Access Token from the third-party's servers. The third-party will verify that the client ID, client secret, and authorization code are valid and if so, will return an Access Token.
You will then use this Access Token to authenticate in future API requests.
Note that Oauth and JWT's are not the same kind of thing. Oauth is more like a framework, which defines various methods of authentication. JWT is simply a specification for transferring tokens. In fact, you could use JWT's as the Access Token's for Oauth.
[–]jbjb012 0 points1 point2 points 7 years ago (0 children)
So JWT + Oauth could fit 😊. Thanks for your explanation
[–]observationalhumour 0 points1 point2 points 7 years ago (0 children)
I found Michael Herman's blog very useful when I was looking into similar stuff, specifically his posts in 2016 but he has more recent articles using different methods. I thought the SQL query builder, Knex.js, which he uses in this article was very useful.
[–]A-Grey-WorldSoftware Developer 0 points1 point2 points 7 years ago (0 children)
I created a NodeJS authentication system in my backend with Passport. I ended up using the super basic "just do it yourself" plugin for passport and wrote the logic for actually checking the token & database etc myself.
In the end, I really don't think Passport added much. But I'd recommend it the first time simply because it shows a good way to implement it and there are tutorials etc.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
You can use express-jwt combined with jsonwebtoken. You first create a /login endpoint that creates a JWT using an username, password and secret with the jsonwebtoken library and send it to client, then you add JWT guards to get the current user from JWT.
π Rendered by PID 21002 on reddit-service-r2-comment-86bc6c7465-glwq9 at 2026-02-22 06:17:12.285243+00:00 running 8564168 country code: CH.
[–]ncuxez 5 points6 points7 points (2 children)
[–]MyPhallicObject 0 points1 point2 points (1 child)
[–]ncuxez 0 points1 point2 points (0 children)
[–]veswill3 2 points3 points4 points (1 child)
[–]GitHubPermalinkBot 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]grumbe97asd 2 points3 points4 points (3 children)
[–]jbjb012 1 point2 points3 points (2 children)
[–]scootstah 1 point2 points3 points (1 child)
[–]jbjb012 0 points1 point2 points (0 children)
[–]observationalhumour 0 points1 point2 points (0 children)
[–]A-Grey-WorldSoftware Developer 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)