simple-login / passportjs-example Goto Github PK
View Code? Open in Web Editor NEWAdd social login support to a Node.js app using passport.js with OpenID Connect (OIDC) strategy
License: MIT License
Add social login support to a Node.js app using passport.js with OpenID Connect (OIDC) strategy
License: MIT License
I am very excited to integrate my first (and probably only) non-local strategy in passport.js though I am having a small issue that has been bugging me for a while. I checked the official SimpleLogin docs to find instructions to integrate SIWSL and it seemed pretty straightforward until I encountered the error TypeError: done is not a function
. I was able to reach the SimpleLogin auth page and logged in but that is where the fun ended. Once reaching the "http:localhost:3000/authorization-code/callback?state=..." route I get that error. This has not been tested in a production environment yet as this error is holding me back.
Can't wait to get this up and running, thank you SimpleLogin team for all the hard work.
const express = require("express");
const config = require('dotenv').config({ path: __dirname + "/.env" });
const bodyParser = require("body-parser");
var _ = require('lodash');
// MODULES
const mongoose = require(__dirname + "/modules/schemas.js").mongoose;
let schemas = require(__dirname + "/modules/schemas.js");
// Authentication
const passport = require('passport');
const passportLocalMongoose = require('passport-local-mongoose');
const OidcStrategy = require('passport-openidconnect').Strategy;
// Start App
const app = express();
const session = require('express-session');
const sess = {
secret: process.env.CRYPT_KEY,
resave: false,
saveUninitialized: false,
cookie: {}
}
if (app.get('env') === 'production') {
app.set('trust proxy', 1) // trust first proxy
sess.cookie.secure = true // serve secure cookies
}
// APP.LISTEN
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ... ` + port));
// APP.USE
app.use(bodyParser.urlencoded({ extended: true }));
// Creating the model
const Entry = mongoose.model("Entry", journalEntrySchema);
const Comment = mongoose.model("Comment", entryCommentSchema);
const User = mongoose.model("User", userSchema);
// Initialize Passport & Session
app.use(session(sess));
app.use(passport.initialize());
app.use(passport.session());
// Create User Strategy for Passport
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
// SimpleLogin Integration
passport.use('oidc', new OidcStrategy({
// SimpleLogin OIDC Settings
issuer: 'https://app.simplelogin.io',
authorizationURL: 'https://app.simplelogin.io/oauth2/authorize',
tokenURL: 'https://app.simplelogin.io/oauth2/token',
userInfoURL: 'https://app.simplelogin.io/oauth2/userinfo',
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
// you might need to change the callbackURL when deploying on production
callbackURL: 'http://localhost:3000/authorization-code/callback',
// openid needs to be in scope
scope: 'openid profile',
}, (issuer, sub, profile, accessToken, refreshToken, done) => {
return done(null, profile);
// ^^^^^^^^^--------------------- ERROR on this line :/
}));
// redirect user to authorization page
app.use('/continue-with-simplelogin', passport.authenticate('oidc'));
// user is redirected back with the *code*
app.use('/authorization-code/callback',
passport.authenticate('oidc', {
failureRedirect: '/error'
}), (req, res) => {
var user = req.user._json
res.send(`
Welcome ${user.name}! <br>
Your email: ${user.email} <br>
Avatar: <img src="${user.avatar_url}">
`)
}
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.