All Projects β†’ eggjs β†’ egg-passport-local

eggjs / egg-passport-local

Licence: MIT license
wrap passport-local strategy for egg-passport

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to egg-passport-local

Nodejs Notes App
A web app to create notes, and save it using Mongodb, plus authentication using passport.
Stars: ✭ 130 (+195.45%)
Mutual labels:  passport
Lad
πŸ‘¦ Lad is the best Node.js framework. Made by a former Express TC and Koa team member.
Stars: ✭ 2,112 (+4700%)
Mutual labels:  passport
Go Guardian
Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.
Stars: ✭ 204 (+363.64%)
Mutual labels:  passport
Laravel Passport Social Grant
πŸ”’ API authentication via social networks for your Laravel application
Stars: ✭ 142 (+222.73%)
Mutual labels:  passport
Roastapp
Laravelε­¦ι™’ Roast 应用源码
Stars: ✭ 164 (+272.73%)
Mutual labels:  passport
Next Postgres Sequelize
React 16.8.4 + NextJS 8.0.3 + Emotion + Sequelize 5/Postgres + Passport Local Auth + Google App Engine or Heroku Deployment
Stars: ✭ 176 (+300%)
Mutual labels:  passport
Laravel Passport Android
Laravel + Passport for an Android App
Stars: ✭ 116 (+163.64%)
Mutual labels:  passport
Builderbook
Open source web application to learn JS stack: React, Material-UI, Next.js, Node.js, Express.js, Mongoose, MongoDB database.
Stars: ✭ 3,015 (+6752.27%)
Mutual labels:  passport
Ecommerce Site Template
A beautiful e-commerce template powered by React, Redux and other modern web tech.
Stars: ✭ 167 (+279.55%)
Mutual labels:  passport
Login With
Stateless login-with microservice for OAuth
Stars: ✭ 2,301 (+5129.55%)
Mutual labels:  passport
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+231.82%)
Mutual labels:  passport
Larapush
artisan push - Deploy your codebase into your web server with one Laravel artisan command and no SSH needed!
Stars: ✭ 150 (+240.91%)
Mutual labels:  passport
Koa Passport Mongoose Graphql
Koa 2 server with Passport + Mongoose + GraphQL
Stars: ✭ 190 (+331.82%)
Mutual labels:  passport
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (+209.09%)
Mutual labels:  passport
Passport
Passport module for Nest framework (node.js) πŸ”‘
Stars: ✭ 211 (+379.55%)
Mutual labels:  passport
Mrz
Machine Readable Zone generator and checker for official travel documents sizes 1, 2, 3, MRVA and MRVB (Passports, Visas, national id cards and other travel documents)
Stars: ✭ 119 (+170.45%)
Mutual labels:  passport
Lighthouse Graphql Passport Auth
Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
Stars: ✭ 173 (+293.18%)
Mutual labels:  passport
core
UBIC: The crypto currency providing UBI for the masses using the E-Passport
Stars: ✭ 37 (-15.91%)
Mutual labels:  passport
Mern Passport
A boilerplate example of using passport.js for authenticating a MERN application
Stars: ✭ 214 (+386.36%)
Mutual labels:  passport
Saas
Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.
Stars: ✭ 2,720 (+6081.82%)
Mutual labels:  passport

egg-passport-local

NPM version build status Test coverage David deps Known Vulnerabilities

Install

$ npm i egg-passport --save
$ npm i egg-passport-local --save

Note: also need egg-passport .

Usage

// {app_root}/config/plugin.js
exports.passport = {
  enable: true,
  package: 'egg-passport',
};

exports.passportLocal = {
  enable: true,
  package: 'egg-passport-local',
};

Configuration

// {app_root}/config/config.default.js
exports.passportLocal = {
  // usernameField: 'username',
  // passwordField: 'password',
};

The available options are:

  • usernameField - Optional, defaults to username
  • passwordField - Optional, defaults to password

Both fields define the name of the properties in the POST body that are sent to the server.

see config/config.default.js for more detail.

after login successful, we can redirect to origin url by using ctx.session.returnTo before go to login page, for example:

ctx.session.returnTo = ctx.path;

Example

see fixture for more detail.

// ./controller/home.js
class HomeController extends Controller {
  async index() {
    const ctx = this.ctx;
    ctx.body = `
      <div>
        <h2>${ctx.path}</h2>
        <a href="https://github.com/admin">admin</a>
      </div>
    `;
  }

  async admin() {
    const { ctx } = this;
    if (ctx.isAuthenticated()) {
      // show user info
    } else {
      // redirect to origin url by ctx.session.returnTo
      ctx.session.returnTo = ctx.path;
      await ctx.render('login.html');
    }
  }

  async logout() {
    const ctx = this.ctx;

    ctx.logout();
    ctx.redirect(ctx.get('referer') || '/');
  }
}
// router.js
module.exports = app => {
  app.router.get('/', 'home.render');
  app.router.get('/admin', 'home.admin');

  const localStrategy = app.passport.authenticate('local');
  app.router.post('/passport/local', localStrategy);

  app.router.get('/logout', 'user.logout');
};

see passport example for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

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].