Skip to content
This repository has been archived by the owner on Oct 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #297 from danielfrg/auth-auth0
Browse files Browse the repository at this point in the history
Add authentication from Auth0
  • Loading branch information
jhpedemonte committed Oct 19, 2016
2 parents e248cf7 + 9f06c7a commit b72e872
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions app/auth-auth0.js
@@ -0,0 +1,64 @@
/**
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
/**
* Example: Passport JS strategy for Auth0.
* Requires additional configuration and npm packages. See
* https://github.com/jupyter-incubator/dashboards_server/wiki/Authentication
* for details.
*/
var url = require('url');
var config = require('./config');
var passport = require('passport');
var Auth0Strategy = require('passport-auth0');

module.exports = function(app) {

app.get('/callback',
passport.authenticate('auth0', { failureRedirect: '/login' }),
function(req, res) {
if (!req.user) {
throw new Error('User name must be set');
}
res.redirect("/");
}
);

app.get('/login',
passport.authenticate('auth0', {}), function (req, res) {
res.redirect("/");
});

app.post('/logout', function(req, res){
req.logout();
var logout_obj_url = {
host: config.get('AUTH0_DOMAIN'),
pathname: '/v2/logout',
query: {
'returnTo': config.get('PUBLIC_LINK_PATTERN'),
'client_id': config.get('AUTH0_CLIENT_ID'),
}
};
var logout_url = url.format(logout_obj_url);
res.redirect(logout_url);
});

var strategy = new Auth0Strategy({
domain: config.get('AUTH0_DOMAIN'),
clientID: config.get('AUTH0_CLIENT_ID'),
clientSecret: config.get('AUTH0_CLIENT_SECRET'),
callbackURL: config.get('AUTH0_CALLBACK_URL')
},
function(accessToken, refreshToken, extraParams, profile, done) {
// accessToken is the token to call Auth0 API (not needed in the most cases)
// extraParams.id_token has the JSON Web Token
// profile has all the information from the user
return done(null, profile);
}
);

// passport.use(strategy);

return strategy;
};

0 comments on commit b72e872

Please sign in to comment.