-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Ground Truth for authentication #264
Conversation
77ac737
to
80c5ee4
Compare
Hey y'all! A deployment of this PR can be found here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to do some functional testing once we get it deployed, but the code so far looks good to me
if (anonymous) { | ||
let email = request.body["anonymous-registration-email"] as string; | ||
let name = request.body["anonymous-registration-name"] as string; | ||
if (await User.findOne({email})) { | ||
if (await User.findOne({ email })) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So walk-up registration will be done completely outside the ground truth flow. If they later created an account that matched this email using ground truth, would the accounts properly sync up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also did registration ever get a chance to allow walk up for people who started an application but didn't finish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joel99 No that's not implemented yet (and I don't think it's covered by an existing issue)
@ehsanmasdar I don't remember if that's the case. We should do some investigating but that shouldn't block HackGT 6 initial release because walk-up won't happen until day-of
if (request.session) { | ||
request.session.loginAction = "render"; | ||
} | ||
response.redirect("/login"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we redirect user to registration login or ground truth login
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would GT know to redirect back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It redirects to /login
so that we can tell the user that they've successfully logged out. If we redirect to Ground Truth, the user will be told to login again even if that isn't what they want to do
} | ||
} | ||
user.accountConfirmed = true; | ||
authRoutes.get("/validatehost/:nonce", (request, response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this? What does this achieve that's not handled by the oauth client library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here because we use the Host
header when generating links and callback URLs in the auth code. This verifies that the server behind the domain in the Host
header is actually us and not some malicious other instance. Not sure if it's overengineered because Host
headers can only be crafted by non-browser HTTP libraries (AJAX requests and JavaScript in browsers cannot override the Host
header)
adding @joel99 would like to get a second set of eyes since it's so critical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehsanmasdar can you help spin up a test deployment so we can QA this?
@petschekr embodying refactor as you go 👍
} | ||
if (process.env.EMAIL_FROM) { | ||
this.email.from = process.env.EMAIL_FROM!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason a lot of these became optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types for Node.js were updated sometime after this code was written to make arbitrary properties on the process.env
object not throw a possibly undefined compiler error. Therefore the non-null assertion operator, !
, is no longer required here (and elsewhere).
if (anonymous) { | ||
let email = request.body["anonymous-registration-email"] as string; | ||
let name = request.body["anonymous-registration-name"] as string; | ||
if (await User.findOne({email})) { | ||
if (await User.findOne({ email })) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also did registration ever get a chance to allow walk up for people who started an application but didn't finish?
if (request.session) { | ||
request.session.loginAction = "render"; | ||
} | ||
response.redirect("/login"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would GT know to redirect back?
// Load and compile Handlebars templates | ||
let [ | ||
indexTemplate, | ||
loginTemplate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there some feature that automatically makes a class variable? How does loadTemplate
get this.file
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor of the Template
class has constructor(private readonly file: string) {}
which makes the first argument when called with new
a private readonly
property automatically. This is shorthand supported by TypeScript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat
@@ -442,14 +462,14 @@ userRoutes.route("/export").get(isAdmin, async (request, response): Promise<void | |||
for (let branchName of await Branches.BranchConfig.getNames()) { | |||
// TODO: THIS IS A PRELIMINARY VERSION FOR HACKGT CATALYST | |||
// TODO: Change this to { "accepted": true } | |||
let attendingUsers: IUserMongoose[] = await User.find({ "applied": true, "applicationBranch": branchName }); | |||
let attendingUsers = await User.find({ "applied": true, "applicationBranch": branchName }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhh should probably fix those TODOs above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehsanmasdar @joel99 Do you think I can just get rid of this /export
endpoint? It's kind of a hidden feature that we haven't used since Catalyst 1 I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, didn't realize that. We have graphiql and checkin2 can do CSV exports, so I'm guessing we don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export data? Yeah, we can grab what we need from db if it becomes relevant if this is an issue. I'd prefer to leave and mark as legacy code for now if it's not blocking, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, lots of long-needed stuff!
Use Ground Truth for authentication
Switches to using HackGT Ground Truth for authentication and removes all auth related code from the codebase.
Ground Truth is implemented as the only login strategy which could make initial setup of registration for organizations that don't already host a Ground Truth instance slightly more complicated. Two possible mitigations:
Fixes #252
Fixes #254
Fixes #262