All Projects → moribvndvs → passport-examples

moribvndvs / passport-examples

Licence: MIT License
A variety of examples using PassportJS with ExpressJS and ReactJS applications

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to passport-examples

express-mvc
A light-weight mvc pattern for express framework with minimum dependencies
Stars: ✭ 23 (-47.73%)
Mutual labels:  mongoose, expressjs, passportjs
node-express-mongo-passport-jwt-typescript
A Node.js back end web application with REST API, user JWT authentication and MongoDB data storage using TypeScript
Stars: ✭ 51 (+15.91%)
Mutual labels:  mongoose, expressjs, passportjs
Quora
Building An Exclusive Community of PEC Graduates and Students.The main features of the website are “PEC Quora” and “PEC Connect”
Stars: ✭ 26 (-40.91%)
Mutual labels:  mongoose, expressjs, axios
Node React Ecommerce
Build ECommerce Website Like Amazon By React & Node & MongoDB
Stars: ✭ 1,080 (+2354.55%)
Mutual labels:  mongoose, expressjs, axios
nodejs-shopping-cart
NodeJS / Express / MongoDB - Shopping Cart (monolithic app with handlebars)
Stars: ✭ 42 (-4.55%)
Mutual labels:  mongoose, handlebars, expressjs
boss
React+express+sock.io+mongodb build a boss
Stars: ✭ 25 (-43.18%)
Mutual labels:  create-react-app, mongoose, axios
react-full-stack-starter
🎈Full-stack React boilerplate using `create-react-app`, Babel, Node.js, and express
Stars: ✭ 22 (-50%)
Mutual labels:  create-react-app, mongoose, expressjs
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+231.82%)
Mutual labels:  mongoose, expressjs, passportjs
MovieGo
A Website implemented using MERN (MongoDB, ExpressJS, ReactJS and NodeJS) stack, which allows users to sign-in/register and book movie tickets online.
Stars: ✭ 26 (-40.91%)
Mutual labels:  mongoose, expressjs, passportjs
mini-express-boilerplate
A minimal Express boilerplate with passport user authentication, mongoose and some security setup configured
Stars: ✭ 15 (-65.91%)
Mutual labels:  mongoose, expressjs, passportjs
trivin
⚡️Setup your entire project quickly and easily with 1-line command ⚡️
Stars: ✭ 58 (+31.82%)
Mutual labels:  mongoose, expressjs, axios
generator-espress
an opinionated yeoman generator that scaffolds a mvc express webapp completely in es6
Stars: ✭ 20 (-54.55%)
Mutual labels:  mongoose, expressjs
react-redux-blog
A MERN Stack CRUD Web Application
Stars: ✭ 36 (-18.18%)
Mutual labels:  mongoose, expressjs
timeoff-server
TimeOff is an application that allows companies' employees to set vacations before they begin taking their time off. Implemented in modern tech stack i.e. Node, Express, MongoDB.
Stars: ✭ 33 (-25%)
Mutual labels:  mongoose, expressjs
task-manager
Task Manager App
Stars: ✭ 19 (-56.82%)
Mutual labels:  mongoose, expressjs
docker-node-mongo-react-STARTER
🐋 🍃 ⚛️ Boilerplate for Node.js, MongoDB, React Applications (with Docker)
Stars: ✭ 34 (-22.73%)
Mutual labels:  mongoose, expressjs
mean-stack
MEAN stack Mongoose, Express, Angular6, Node
Stars: ✭ 22 (-50%)
Mutual labels:  mongoose, expressjs
typescript-express-passportjs
ExpressJs project uses TypeScript, PassportJS, Moongose, Continuous Integration (CircleCI.io) and Code Coverage (CodeCov.io)
Stars: ✭ 14 (-68.18%)
Mutual labels:  expressjs, passportjs
inventory-demo
a simple MERN stack CRUD app example
Stars: ✭ 15 (-65.91%)
Mutual labels:  mongoose, expressjs
express-mvc-generator
Express' Model View Controller Application Generator.
Stars: ✭ 46 (+4.55%)
Mutual labels:  mongoose, expressjs

PassportJS Examples

This repository contains several example configurations using PassportJS as authentication middleware. PassportJS is very flexible, at a cost of being a bit confusing to set up and tailor to your particular application's needs.

Please note this repository is NOT a conclusive or exhaustive list of ways you can leverage PassportJS.

Project Structure

To save myself time and typing, I will reuse as much code as possible. I will also make each example as simple as possible while demonstrating functionality and proper structure.

Here's what's inside:

  • shared: This folder contains any code that is shared between all the examples, like user models and utilities.
  • shared/middleware: This folder contains any common middleware for setting up internals of the server, like connecting to mongoose.
  • shared/models: This folder contains any common mongoose models, most importantly it has our User model.

Examples

  • example-simple: A very simple Express server that uses Handlebars and basic form posts to authenticate users using the passport-local strategy. See the README in that folder for more info.
  • example-simple-react: A very simple express server that uses React and the passport-local strategy. This example also shows a way to ensure someone can't access a route unless they are logged in (see /shared/middleware/mustBeLoggedIn.js). This could actually be used in any express server using passport on any route.
  • example-social-media-react: A refinement of the simple React app, but supports multiple social media logins in addition to username/password. As an added bonus, it shows how to use access tokens provided by the social media site's passport strategy to access the user's data from the social media site's API. In this example, users that log in via Spotify can retrieve their playlists, and likewise for Twitter users' tweets.

Miscellaneous

  • Any examples that use server-side template rendering are using Handlebars. Pug is better :), but this set of examples was built primarily for Bootcamp students that were taught Handlebars. Using Pug instead is quite easy, but that exercise is left to you at the moment.

What is PassportJS

PassportJS is a Node package intended to be used with the ExpressJS web applications. It can be dropped into your application to add authentication support. Your application will instruct PassportJS to use one or more Strategies.

Strategies

A Strategy is like middleware for PassportJS that attempts to authenticate a user based on a request. How the Strategy authenticates a user is dependent on the Strategy implementation you decide to use. Strategies can vary from simple, such as LocalStrategy who simply authenticates a user using username/password against your application (usually using a database), to a more complex strategy using OAuth 2 that allows users to log in using a socia media account. There are 500+ strategies, so the place to start is determining how you want users to be able to authenticate. Start simple and add from there; remember that your app is allowed to use several strategies.

Do you want users to be able to sign up using username and password?

Use the passport-local package for the LocalStrategy. Users will simply authenticate using a username and password, and you'll configure the strategy on how to find the user in your database and then check the provided password is correct.

Caveat: This is effectively managing the account's username and password inside your application. Security is HARD and absolutely CRITICAL. So if you're not ready for secure password management, go with a social media identity provider (Google, Twitter, Facebook, etc.) instead. Additionally, if your app will only work by accessing a user's data on a social media site, then you should not use LocalStrategy, but the strategy for that social media site.

Do you need to access a social media API on behalf of a user?

Use the appropriate strategy for the social media site. Here are some common strategies:

Do you want to have a mix of local and social media accounts, or have advanced API authentication requirements and don't want to do all the auth code yourself?

Consider signing up for Auth0. Security is hard, and if you're not comfortable doing it or ready to take on the responsibility, let the pros do it for you. It's free to start, can secure your APIs, and allows you to easily implement authentication using any variety of identity providers, including custom username/password database, Facebook, Google, etc. Auth0 does the heavy lifting for securely managing credentials, OAuth 2 exchanges between your apps and the identity providers, and all you need to do is drop a little code and some config values into your app. It also makes many other advanced authn/authz tasks easy for you, like SSO, SAML, and a whole slew of other things.

The Auth0 team has provided the passport-auth0 to drop into your app. You can get more detailed and ready-to-cut-and-paste code once you create an account and create your first client in your account.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].