This repository was archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
[Tech debt] Refactor authService and remove LogInHelper #588
Merged
Conversation
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
@MGibson1 I think I've now refactored this to within an inch of its life. Summary of further changes:
I'm happier with how this is looking now. |
MGibson1
approved these changes
Jan 27, 2022
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'm going to tag this with a hold until we can confirm with QA on merging
|
This was referenced Feb 1, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Objective
AuthService
is a bit of a mess because the privatelogInHelper
method contains code used by every single type of authentication (e.g. MP, SSO, API, 2FA). This makes it extremely difficult to reason about what type of authentication calls what code, where new code should go, and when code can be removed.This refactor aims to improve this by:
Code changes
Peripheral changes
Here are the smaller/peripheral changes you should understand first.
Models:
tokenRequest
an abstract base classpasswordTokenRequest
,apiTokenRequest
,ssoTokenRequest
. Extract specific code into the subclasses.TokenRequestTwoFactor
(defined in the basetokenRequest
file)authResult
: add getters. Remove thetwoFactor
property because we can calculate this information rather than storing it.Other services:
KeyConnectorService
: this now has the code that enrols a new SSO user in Key Connector, which used to be handled byauthService
. This could likely be refactored/combined withmigrateUser
(which handles converting existing users), but that's out of scope for now.TwoFactorService
: a new service which handles the two factor-related operations that were previously inAuthService
. This reduces the amount thatAuthService
is responsible for given that it's already quite complex.TokenService
: this interface did not match the implementation. I assume this is an oversight from account switching. I've updated the interface accordingly.ApiService
: update to use the newtokenService
interface. Remove the null coalescing when creating the identity token string, this is handled by the subclasses.CLI
login.command.ts
: this used to be a 6-pronged conditional, which called either the standard login methods (LogIn
,LogInApi
,LogInSso
) if no 2FA was provided, or the*Complete
version of those methods if 2FA was provided. This has been simplified to just call those 3 standard login methods, and they will handle whether or not 2FA is provided.Angular components:
AuthService changes
LogInComplete
,LogInSsoComplete
, andLogInApiComplete
. These were called by the CLI client if the user provided 2FA info upfront. Now we usebuildTwoFactor
to handle those situations, and we don't need separate entry methods.apiLogInDelegate
,passwordLogInDelegate
andssoLogInDelegate
, plus their common base class. The base class has the common logic and the subclasses provide their own implementations as required, depending on the login method used. This is where theLogInHelper
code has been moved to.authService
is now only responsible for creating and initializing the correct delegate class and asking it to start the login process. It's essentially the factory for the different implementations.I don't know if "delegate" is the correct verbiage here, but it's neither a service (which are long-lived and initialized during bootstrapping) nor a model (which only manipulate data and shouldn't have service dependencies). I've stuck them in the
misc
folder for this reason.Tests
Add tests. My first tests were very broad and contained lots of overlapping assertions, just as guardrails while I was refactoring. Once I finished refactoring, I rewrote them to test the specific behaviour that is expected of each delegate.
Other clients
Testing requirements
This will require really comprehensive regression testing of all login methods and combinations. Here are the code paths I can think of that I've touched:
Before you submit
npm run lint
) (required)