Skip to content
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

Adding Authentication to API #12

Merged
merged 76 commits into from
Jun 23, 2021
Merged

Adding Authentication to API #12

merged 76 commits into from
Jun 23, 2021

Conversation

MikeDrewitt
Copy link
Member

@MikeDrewitt MikeDrewitt commented Jun 13, 2021

Proposed changes


Adding auth providers to the api. Currently we've implemented a SAML provider (for school auth) as well as a local development only provider that allows you to input which user you want to login as. The configuration options for both of these things are controlled via .yml files in the new config directory.

Due to using passport as a middleware for auth, we had to remove our user model from extending the express request type because it conflicted with passports (so stupid, we know). To compensate, we've decided that serializers will no longer act as middleware, and should instead just be called from the controller, and for controllers to (for the most part) become the last piece of middleware in the chain. After implementing this, tbh it probably should have been implemented this way from the start as it's much less obtuse as to what's going on in a controller.

In order to run this locally, you'll have to generate a config for yourself to encode and decode jwts. There's a new command, and documentation in the package json and readme respectively to learn yourself on how to make that happen.

I'm sure we're forgetting more than a few things in this list of stuff, so please please please ask lots and lots of questions.

There are sister PRs for both the client and shared repositories as well that will go up within in a few minutes of this PR going live, and I'd encourage everyone looking at this, to check that out as well.

Client PR - UBAutograding/devU-client#3
Shared PR -UBAutograding/devu-shared#1

Types of changes


  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist


  • My changeset covers only what is described above (no extraneous changes)
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged downstream

Further comments


This is a giant PR, and the absolute definition of "do as I say, not as I do". Under normal circumstances I wouldn't want to put up a PR that touches so much code. But because of how fundamental auth is to the underlying systems, it was fairly necessary.

What was less necessary was refactoring and changing the way that some of the project is structured and named, very sorry about that. Because the project is still in it's infancy, and this is our first "real" foray into the project, we noticed a bunch of things that should (and were) changed (mostly in regards to naming), to (hopefully) make the project easier to maintain, and easier to work in moving forward. It's just a shame these things weren't thought about until we really got into things.

MikeDrewitt and others added 22 commits June 10, 2021 19:06
 - Added `BYPASS_SCHOOL_AUTH` as option to skip school auth (when developing)
 - Added auth service to deal with creating and checking validation
 - Added ensure user function to get or create a user based on schools auth info
 - Added /login to user controller
 - Updated user.schoolId to be unique in DB
 - Added new shared types (for use in client)

 - Enabled strict null checking (this should have been on from the start)
 - Fixed some errors that the compiler told me about once that was on
  - Potentially missing status codes in serializers
  - issues with querying in the users.service
Adds additional JWT fields for validation as well as ensures that
the signing algorithms and keys are validated. Additional changes
and cleanup to come.

---WIP---
Currently in a working state - however additional validation needs
to be performed and lots of cleanup/restructure to follow.
(Consider collapsing all the x.config.json files into a single yaml
config file organized by domain with optional ENV var overrides for
each?)
Fixed issue with json body not being seen on the request
Updated developer provider settings
Added developer login validations
Updated login routes to follow above changes
Implements saml metadata endpoint for pulling SP metadata by the IDP
 - Added `BYPASS_SCHOOL_AUTH` as option to skip school auth (when developing)
 - Added auth service to deal with creating and checking validation
 - Added ensure user function to get or create a user based on schools auth info
 - Added /login to user controller
 - Updated user.schoolId to be unique in DB
 - Added new shared types (for use in client)

 - Enabled strict null checking (this should have been on from the start)
 - Fixed some errors that the compiler told me about once that was on
  - Potentially missing status codes in serializers
  - issues with querying in the users.service
Copy link
Member

@daviddob daviddob left a comment

Choose a reason for hiding this comment

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

This PR is massive, but necessary - hopefully going forward we can break them up a bit 😃

Few questions and comments to address but this is pretty solid.

.gitignore Show resolved Hide resolved
config/default.yml.template Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
config/default.yml Outdated Show resolved Hide resolved
config/test.yml Outdated Show resolved Hide resolved
src/router/login.router.ts Outdated Show resolved Hide resolved
src/router/users.router.ts Show resolved Hide resolved
src/services/user.service.ts Show resolved Hide resolved
src/utils/passport/saml.passport.ts Outdated Show resolved Hide resolved
src/utils/testing.utils.ts Show resolved Hide resolved
jpobzy and others added 15 commits June 17, 2021 15:56
# Conflicts:
#	.gitignore
#	.vscode/launch.json
#	@types/express/index.d.ts
#	config/default.yml.template
#	package-lock.json
#	package.json
#	scripts/generateConfig.sh
#	src/controller/login.controller.ts
#	src/controller/login.developer.controller.ts
#	src/controller/login.saml.controller.ts
#	src/environment.ts
#	src/index.ts
#	src/middleware/auth.middleware.ts
#	src/middleware/serializer/tests/users.serializer.test.ts
#	src/middleware/serializer/users.serializer.ts
#	src/migration/1623375449310-tightenUpUserModel.ts
#	src/router/login.developer.router.ts
#	src/router/login.router.ts
#	src/router/login.saml.router.ts
#	src/services/auth.service.ts
#	src/utils/passport.utils.ts
#	src/utils/passport/saml.passport.ts
#	tsconfig.json
Typeos from github

Co-authored-by: David Dobmeier <[email protected]>
@daviddob daviddob merged commit 93b2f75 into master Jun 23, 2021
@daviddob daviddob deleted the auth branch June 23, 2021 02:02
daviddob added a commit that referenced this pull request Jun 23, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
daviddob added a commit that referenced this pull request Jun 23, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
daviddob added a commit that referenced this pull request Jun 23, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
jessehartloff pushed a commit that referenced this pull request Jun 29, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
jessehartloff pushed a commit that referenced this pull request Jun 30, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
jessehartloff pushed a commit that referenced this pull request Jul 19, 2021
Implemented initial developer auth + SAML flows for authentication, uses JWT for tokens

Co-authored-by: Michael Drewitt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants