Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Use Auth0 hosted login page. #12

Merged
merged 14 commits into from
Feb 16, 2018
Merged

Use Auth0 hosted login page. #12

merged 14 commits into from
Feb 16, 2018

Conversation

xoen
Copy link
Contributor

@xoen xoen commented Feb 13, 2018

What

This should also mean a user logged in other part of the platform
will be already logged in (SSO)

Refactorings (or lack of)

I'm not a great fan of massive refactoring. I focused on adding the feature.

The only thing I tweaked was adding a bit more logging to the middleware module which I also renamed to authorisation as that's what it does so it should be named accordingly.

Ticket

https://trello.com/c/t90fEmBs/647-4-update-rstudio-auth-proxy-to-use-hosted-auth0-login

This should also mean a user logged in other part of the platform
will be already logged in (SSO)

Ticket: https://trello.com/c/t90fEmBs/647-4-update-rstudio-auth-proxy-to-use-hosted-auth0-login
@xoen xoen added the wip label Feb 13, 2018
app/config.js Outdated
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
callbackURL: process.env.AUTH0_CALLBACK_URL || 'http:https://localhost:3000/callback'
domain: process.env.AUTH0_DOMAIN,
scope: 'openid profile',
Copy link
Contributor Author

@xoen xoen Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added scope and passReqToCallback here. Sorted the keys.

This module was dealing with authorisation, so it should be named
accordingly.
We only use the user nickname to check if it's authorised to
access RStudio. This field should come from from the `profile` scope.

SEE: https://auth0.com/docs/scopes/current
@xoen xoen force-pushed the ag--auth0-hosted-login-page branch from 16488d6 to df308e3 Compare February 14, 2018 10:52
@xoen xoen removed the wip label Feb 14, 2018
Copy link
Contributor

@andyhd andyhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just minor comments

} else {
res.sendStatus(403);
next(new Error('User is not authorized'));
}
};

function isAuthorized(req) {
function _isAuthorized(req) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to prefix Javascript functions with _ - that is a Python idiom indicating that a function or method is intended to be private.
All functions in Javascript are private to the module unless explicitly exported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this pass eslint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have eslint running in this project. I'll add the lint task and see what I can savage.

} catch (error) {
// do nothing
log.error('Error while checking user nickname: ', error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this output anything useful? You might need to do JSON.stringify(error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this yesterday by manually throw a weird json-y exception and bole escaped it correctly (which is great). I think log this is not a bad idea as this is kind of a programming error (e.g. the token doesn't include the nickname field).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

app/index.js Outdated
@@ -25,12 +25,15 @@ nunjucks.configure(path.join(__dirname, 'views'), {
app.use(require('cookie-parser')());
app.use(require('express-session')(config.session));

passport.use(new Auth0Strategy(
strategy = new Auth0Strategy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sould be const strategy = or at least var strategy =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

app/routes.js Outdated
@@ -1,36 +1,52 @@
var config = require('./config');
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
var express = require('express');
var middleware = require('./middleware');
var authorisation = require('./authorisation');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be spelled authorization. The concept of authorization in technology is abbreviated to "authz", and it is already spelled -ize in existing code in middleware.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always confused me as in American they use zs but in UK we use ses.

In the company were I used to work they preferred ses because "we're in UK innit?" - should we stick with the American spelling or the British one? (not that I mind either way)

I'll change to the z here then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was another word, I don't think I would have mentioned it. But authorization is AuthZ (and authentication is AuthN), so I think in this case it's worth being consistent and using the z spelling.

app/routes.js Outdated
}
} else {
passport.authenticate('auth0-oidc', {
state: uuidv4(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does state need to be passed here? If passport does not generate a state value by default, does it check one if supplied? Otherwise, the UUID should be stored in the session and checked in the callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tested without the state and seems to work so I'll remove this and the dependency (hopefully we'll not regret this :D)

app/routes.js Outdated
}

router.get('/logout', logout);
router.get('/auth-sign-out', logout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, you can do

router.get(['/logout', '/auth-sign-out'], (req, res) => {
  ...
});

@xoen
Copy link
Contributor Author

xoen commented Feb 14, 2018

@andyhd I made few changes to address your comments, please have another look, focus particularly on the changes in the last 9 commits (a lot of noise as I linted some of the files). Cheers

This is necessary as we're starting to use ES6 for some of the code.
@xoen xoen merged commit 333c205 into master Feb 16, 2018
@xoen xoen deleted the ag--auth0-hosted-login-page branch February 16, 2018 09:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants