refactor: simplify UIA stage selection logic

(Also prevents a potential out of bounds exception)
This commit is contained in:
Nicolas Werner 2023-07-31 17:15:23 +02:00
parent 334c9e3b78
commit 59693b7375
No known key found for this signature in database
1 changed files with 5 additions and 11 deletions

View File

@ -102,17 +102,11 @@ class UiaRequest<T> {
List<AuthenticationFlow> flows, List<String> completed) { List<AuthenticationFlow> flows, List<String> completed) {
final nextStages = <String>{}; final nextStages = <String>{};
for (final flow in flows) { for (final flow in flows) {
final stages = flow.stages; // check the flow starts with the completed stages
final nextStage = stages[completed.length]; if (flow.stages.length >= completed.length &&
var stagesValid = true; flow.stages.take(completed.length).toSet().containsAll(completed)) {
for (var i = 0; i < completed.length; i++) { final stages = flow.stages.skip(completed.length);
if (stages[i] != completed[i]) { if (stages.isNotEmpty) nextStages.add(stages.first);
stagesValid = false;
break;
}
}
if (stagesValid) {
nextStages.add(nextStage);
} }
} }
return nextStages; return nextStages;