-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TRN verification elevation journey
- Loading branch information
Showing
35 changed files
with
970 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
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
82 changes: 82 additions & 0 deletions
82
...-authserver/src/TeacherIdentity.AuthServer/Journeys/ElevateTrnVerificationLevelJourney.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Diagnostics; | ||
|
||
namespace TeacherIdentity.AuthServer.Journeys; | ||
|
||
public class ElevateTrnVerificationLevelJourney : SignInJourney | ||
{ | ||
private readonly TrnLookupHelper _trnLookupHelper; | ||
|
||
public ElevateTrnVerificationLevelJourney( | ||
TrnLookupHelper trnLookupHelper, | ||
HttpContext httpContext, | ||
IdentityLinkGenerator linkGenerator, | ||
UserHelper userHelper) : | ||
base(httpContext, linkGenerator, userHelper) | ||
{ | ||
_trnLookupHelper = trnLookupHelper; | ||
} | ||
|
||
public static string GetStartStepUrl(IdentityLinkGenerator linkGenerator) => linkGenerator.ElevateLanding(); | ||
|
||
public async Task LookupTrn() | ||
{ | ||
var trn = await _trnLookupHelper.LookupTrn(AuthenticationState); | ||
Debug.Assert(AuthenticationState.TrnVerificationElevationSuccessful.HasValue); | ||
|
||
if (trn is not null) | ||
{ | ||
Debug.Assert(AuthenticationState.TrnVerificationElevationSuccessful == true); | ||
await UserHelper.ElevateTrnVerificationLevel(AuthenticationState.UserId!.Value, trn, AuthenticationState.NationalInsuranceNumber!); | ||
} | ||
else | ||
{ | ||
Debug.Assert(AuthenticationState.TrnVerificationElevationSuccessful == false); | ||
await UserHelper.SetNationalInsuranceNumber(AuthenticationState.UserId!.Value, AuthenticationState.NationalInsuranceNumber!); | ||
} | ||
} | ||
|
||
public override bool CanAccessStep(string step) => step switch | ||
{ | ||
Steps.Landing => true, | ||
CoreSignInJourneyWithTrnLookup.Steps.NiNumber => true, | ||
CoreSignInJourneyWithTrnLookup.Steps.Trn => AuthenticationState.HasNationalInsuranceNumber == true, | ||
Steps.CheckAnswers => AuthenticationState.HasNationalInsuranceNumber == true && AuthenticationState.StatedTrn is not null, | ||
_ => false | ||
}; | ||
|
||
protected override string? GetNextStep(string currentStep) => currentStep switch | ||
{ | ||
Steps.Landing => CoreSignInJourneyWithTrnLookup.Steps.NiNumber, | ||
CoreSignInJourneyWithTrnLookup.Steps.NiNumber => CoreSignInJourneyWithTrnLookup.Steps.Trn, | ||
CoreSignInJourneyWithTrnLookup.Steps.Trn => Steps.CheckAnswers, | ||
_ => null | ||
}; | ||
|
||
protected override string? GetPreviousStep(string currentStep) => currentStep switch | ||
{ | ||
CoreSignInJourneyWithTrnLookup.Steps.NiNumber => Steps.Landing, | ||
CoreSignInJourneyWithTrnLookup.Steps.Trn => CoreSignInJourneyWithTrnLookup.Steps.NiNumber, | ||
Steps.CheckAnswers => CoreSignInJourneyWithTrnLookup.Steps.Trn, | ||
_ => null | ||
}; | ||
|
||
protected override string GetStartStep() => Steps.Landing; | ||
|
||
protected override string GetStepUrl(string step) => step switch | ||
{ | ||
Steps.Landing => LinkGenerator.ElevateLanding(), | ||
CoreSignInJourneyWithTrnLookup.Steps.NiNumber => LinkGenerator.RegisterNiNumber(), | ||
CoreSignInJourneyWithTrnLookup.Steps.Trn => LinkGenerator.RegisterTrn(), | ||
Steps.CheckAnswers => LinkGenerator.ElevateCheckAnswers(), | ||
_ => throw new ArgumentException($"Unknown step: '{step}'.") | ||
}; | ||
|
||
// We're done when we've done a lookup, successful or not, using the Strict TrnMatchPolicy | ||
protected override bool IsFinished() => AuthenticationState.TrnVerificationElevationSuccessful.HasValue; | ||
|
||
public new static class Steps | ||
{ | ||
public const string Landing = $"{nameof(ElevateTrnVerificationLevelJourney)}.{nameof(Landing)}"; | ||
public const string CheckAnswers = $"{nameof(ElevateTrnVerificationLevelJourney)}.{nameof(CheckAnswers)}"; | ||
} | ||
} |
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
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
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
Oops, something went wrong.