All Projects → pandark → passport-42

pandark / passport-42

Licence: MIT license
Passport strategy for authenticating with 42 using the OAuth 2.0 API

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to passport-42

42header.vim
Add and update the 42 comment header at the top of your files
Stars: ✭ 15 (-42.31%)
Mutual labels:  42born2code, 42, 42school
1337
This repository contains a collection of 42School cursus projects in addition to the pool/piscine days (with a detailed step by step explanation). Enjoy!
Stars: ✭ 35 (+34.62%)
Mutual labels:  42born2code, 42, 42school
42ShellTester
Integration test suite for Shell implementation
Stars: ✭ 35 (+34.62%)
Mutual labels:  42born2code, 42, 42school
minishell tester
42 | Complex tester for minishell (42cursus)
Stars: ✭ 31 (+19.23%)
Mutual labels:  42born2code, 42, 42school
42 Projects
What is 42? How does curriculum look like? A manual reference for all 42 projects I've done so far (Zappy, Malloc, C++ Piscine... check out for more)! 💡📈
Stars: ✭ 111 (+326.92%)
Mutual labels:  42born2code, 42, 42school
42MapGenerator
Generate FdF maps of the real world, the Earth's moon and the planet Venus for the project Fil de Fer
Stars: ✭ 58 (+123.08%)
Mutual labels:  42born2code, 42, 42school
init
School 42 project // DevOps project
Stars: ✭ 13 (-50%)
Mutual labels:  born2code, 42, 42school
ft get next line
42 São Paulo - get_next_line
Stars: ✭ 17 (-34.62%)
Mutual labels:  42born2code, 42, 42school
react-node-twitter-login
Demo application that shows how to enable Twitter login with React on frontend and Node.js/Express on backend
Stars: ✭ 34 (+30.77%)
Mutual labels:  passport, 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 (+96.15%)
Mutual labels:  passport, passportjs
Passport Spotify
Spotify authentication strategy for Passport and Node.js.
Stars: ✭ 266 (+923.08%)
Mutual labels:  passport, passportjs
ExpressJS-SocketIO-Boilerplate
📦 Simple Express.js & Socket.io Boilerplate
Stars: ✭ 31 (+19.23%)
Mutual labels:  passport, passportjs
passport-saml-example
PassportJS SAML example
Stars: ✭ 118 (+353.85%)
Mutual labels:  passportjs, passport-js
examrank-02-03-04-05-06
exam project 2020
Stars: ✭ 195 (+650%)
Mutual labels:  42born2code, 42school
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (+130.77%)
Mutual labels:  passport, passportjs
IRC-Server
IRC server based on TCP/IP protocol to rfc1459 standard
Stars: ✭ 27 (+3.85%)
Mutual labels:  42born2code, 42school
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+461.54%)
Mutual labels:  passport, passportjs
42tools
Making 42 life better
Stars: ✭ 43 (+65.38%)
Mutual labels:  42born2code, 42
vue-nuxt-passport-bulma-express-boiler
A Vue+Vuex starter with Nuxt scaffolding, Bulma styling, and Express backend.
Stars: ✭ 21 (-19.23%)
Mutual labels:  passport, passport-js
react-redux-passport-uikit-express-boiler
A React+Redux boilerplate using Express as backend, UIKit for frontend, MongoDB for storage & Passport for auth.
Stars: ✭ 59 (+126.92%)
Mutual labels:  passport, passportjs

passport-42

Build Coverage Quality Greenkeeper badge Dependencies

Passport strategy for authenticating with 42 using the OAuth 2.0 API.

This module lets you authenticate using 42 in your Node.js applications. By plugging into Passport, 42 authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-42

Usage

Create an Application

Before using passport-42, you must register an application with 42. If you have not already done so, a new application can be created at 42 Applications. Your application will be issued an app UID and app SECRET, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your application.

Configure Strategy

The 42 authentication strategy authenticates users using a 42 account and OAuth 2.0 tokens. The app UID and SECRET obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's 42 profile. The verify callback must call cb providing a user to complete authentication.

var FortyTwoStrategy = require('passport-42').Strategy;

passport.use(new FortyTwoStrategy({
    clientID: FORTYTWO_APP_ID,
    clientSecret: FORTYTWO_APP_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/42/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ fortytwoId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the '42' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/42',
  passport.authenticate('42'));

app.get('/auth/42/callback',
  passport.authenticate('42', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Examples

Developers using the popular Express web framework can refer to an example as a starting point for their own web applications.

Options

Specify profile fields

The 42 profile contains a lot of information about a user. The fields needed by an application can be indicated by setting the profileFields option.

new FortyTwoStrategy({
  clientID: FORTYTWO_APP_ID,
  clientSecret: FORTYTWO_APP_SECRET,
  callbackURL: "http://127.0.0.1:3000/auth/42/callback",
  profileFields: {
    'id': function (obj) { return String(obj.id); },
    'username': 'login',
    'displayName': 'displayname',
    'name.familyName': 'last_name',
    'name.givenName': 'first_name',
    'profileUrl': 'url',
    'emails.0.value': 'email',
    'phoneNumbers.0.value': 'phone',
    'photos.0.value': 'image_url'
  }
}), ...)

Refer to the User 42 API Reference for the complete set of available fields.

User agent

Although 42 API doesn't require a user agent in the requests header, passport-42 sets one, by default "passport-42". You can set a different one using the userAgent option.

Contributing

Tests

The test suite is located in the test/ directory. All new features are expected to have corresponding test cases. Ensure that the complete test suite passes by executing:

$ make test

Coverage

The test suite covers 100% of the code base. All new feature development is expected to maintain that level. Coverage reports can be viewed by executing:

$ make test-cov
$ make view-cov

License

The MIT License

Copyright (c) 2016 Adrien "Pandark" Pachkoff <https://lifeleaks.com/>

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