This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added optional auth0 authentication, and public registration toggle
- Loading branch information
1 parent
b4a40f4
commit 4153071
Showing
11 changed files
with
690 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,12 @@ SMPT_PASSWORD="" | |
# providers will require to verify your domain first. | ||
EMAIL_SENDER="[email protected]" | ||
|
||
# Set to false to disable register routes | ||
PUBLIC_REGISTRATION=false | ||
|
||
# Auth0 | ||
USE_AUTH0=false | ||
AUTH0_CLIENT_ID=XXX | ||
AUTH0_DOMAIN=XXX | ||
AUTH0_CLIENT_SECRET=XXX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict' | ||
const exphbs = require( 'express-handlebars' ) | ||
const passport = require( 'passport' ) | ||
const Auth0Strategy = require( 'passport-auth0' ) | ||
|
||
module.exports = function ( app, express ) { | ||
|
||
app.engine( '.hbs', exphbs( { extname: '.hbs' } ) ) | ||
app.set( 'view engine', '.hbs' ) | ||
|
||
// delegate user identity verification to auth0 | ||
if ( process.env.USE_AUTH0 === "true" ) { | ||
|
||
addAuth0Strategy( ) | ||
|
||
// all routes should go to the auth0 lock screen | ||
app.get( '/register', ( req, res ) => res.render( 'auth0', { layout: false, title: 'Speckle: Login/Register to your account', clientId: process.env.AUTH0_CLIENT_ID, domain: process.env.AUTH0_DOMAIN } ) ) | ||
|
||
app.get( '/login', ( req, res ) => res.render( 'auth0', { layout: false, title: 'Speckle: Login/Register to your account', clientId: process.env.AUTH0_CLIENT_ID, domain: process.env.AUTH0_DOMAIN } ) ) | ||
|
||
app.get( '/registration-callback', passport.authenticate('auth0'), handlePassportRegistration ) | ||
|
||
} else { | ||
|
||
// not delegating user identity | ||
|
||
if ( process.env.PUBLIC_REGISTRATION === "true" ) | ||
app.get( '/register', ( req, res ) => res.render( 'register', { | ||
title: 'Register a new speckle account', | ||
server: process.env.SERVER_NAME, | ||
url: process.env.CANONICAL_URL | ||
} ) ) | ||
|
||
app.get( '/login', ( req, res ) => res.render( 'login', { | ||
title: 'Login to your speckle account', | ||
server: process.env.SERVER_NAME, | ||
url: process.env.CANONICAL_URL | ||
} ) ) | ||
} | ||
} | ||
|
||
function handlePassportRegistration( req, res ) => { | ||
res.send( req.user ) | ||
} | ||
|
||
function addAuth0Strategy( ) { | ||
|
||
let strategy = new Auth0Strategy( { | ||
domain: process.env.AUTH0_DOMAIN, | ||
clientID: process.env.AUTH0_CLIENT_ID, | ||
clientSecret: process.env.AUTH0_CLIENT_SECRET, | ||
state: false, | ||
callbackURL: '/registration-callback' | ||
}, ( accessToken, refreshToken, extraParams, profile, done ) => done( null, profile ) ) | ||
|
||
passport.use( strategy ) | ||
passport.serializeUser( ( user, done ) => done( null, user ) ) | ||
passport.deserializeUser( ( user, done ) => done( null, user ) ) | ||
|
||
} |
Oops, something went wrong.