Merge pull request #1534 from famedly/nico/simplify-sorting

refactor: simplify UIA stage selection logic
This commit is contained in:
Nicolas Werner 2023-08-01 08:56:56 +00:00 committed by GitHub
commit 4addccd9da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 11 deletions

View File

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