Skip to content

TypeError: done is not a function #2

@elisavetsky

Description

@elisavetsky

Preface

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.

My troublesome code

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}">
    	`)
	}
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions