TF-3826 Try guessing webfinger when dns look up fail
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||
|
||||
enum OidcGuessingOrigin {
|
||||
empty(origin: ''),
|
||||
autoDiscover(origin: 'autodiscover'),
|
||||
jmap(origin: 'jmap');
|
||||
|
||||
const OidcGuessingOrigin({required this.origin});
|
||||
|
||||
final String origin;
|
||||
|
||||
String url(String email) {
|
||||
if (!EmailUtils.isEmailAddressValid(email)) {
|
||||
throw ArgumentError('Invalid email address: $email');
|
||||
}
|
||||
final emailDomain = email.split('@').last;
|
||||
return switch (this) {
|
||||
OidcGuessingOrigin.empty => 'https://$emailDomain',
|
||||
_ => origin.trim().isEmpty
|
||||
? OidcGuessingOrigin.empty.url(email)
|
||||
: 'https://$origin.$emailDomain',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,10 @@ class DNSLookupToGetJmapUrlSuccess extends UIState {
|
||||
}
|
||||
|
||||
class DNSLookupToGetJmapUrlFailure extends FeatureFailure {
|
||||
DNSLookupToGetJmapUrlFailure(
|
||||
dynamic exception, {
|
||||
required this.email,
|
||||
}) : super(exception: exception);
|
||||
|
||||
DNSLookupToGetJmapUrlFailure(dynamic exception) : super(exception: exception);
|
||||
final String email;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/oidc/response/oidc_response.dart';
|
||||
|
||||
class TryingGuessingWebFinger extends LoadingState {}
|
||||
|
||||
class TryGuessingWebFingerSuccess extends UIState {
|
||||
TryGuessingWebFingerSuccess(this.oidcResponse);
|
||||
|
||||
final OIDCResponse oidcResponse;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [oidcResponse];
|
||||
}
|
||||
|
||||
class TryGuessingWebFingerFailure extends FeatureFailure {
|
||||
TryGuessingWebFingerFailure({super.exception});
|
||||
}
|
||||
@@ -15,7 +15,10 @@ class DNSLookupToGetJmapUrlInteractor {
|
||||
final jmapUrl = await _loginRepository.dnsLookupToGetJmapUrl(emailAddress);
|
||||
yield Right<Failure, Success>(DNSLookupToGetJmapUrlSuccess(jmapUrl));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(DNSLookupToGetJmapUrlFailure(e));
|
||||
yield Left<Failure, Success>(DNSLookupToGetJmapUrlFailure(
|
||||
e,
|
||||
email: emailAddress,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'dart:async';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/oidc/request/oidc_request.dart';
|
||||
import 'package:model/oidc/response/oidc_response.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/try_guessing_web_finger_state.dart';
|
||||
|
||||
class TryGuessingWebFingerInteractor {
|
||||
const TryGuessingWebFingerInteractor(this._authenticationOIDCRepository);
|
||||
|
||||
final AuthenticationOIDCRepository _authenticationOIDCRepository;
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
List<OIDCRequest> oidcRequests,
|
||||
) async* {
|
||||
try {
|
||||
yield Right(TryingGuessingWebFinger());
|
||||
final futures = oidcRequests.map(_checkOIDCAvailableFromOidcRequest).toList();
|
||||
final completer = Completer<OIDCResponse?>();
|
||||
|
||||
for (final future in futures) {
|
||||
future.then((response) {
|
||||
if (response != null && !completer.isCompleted) {
|
||||
completer.complete(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future.wait(futures).then((_) {
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete(null);
|
||||
}
|
||||
});
|
||||
|
||||
final firstNonNullResponse = await completer.future;
|
||||
|
||||
if (firstNonNullResponse == null) {
|
||||
yield Left(TryGuessingWebFingerFailure());
|
||||
} else {
|
||||
yield Right(TryGuessingWebFingerSuccess(firstNonNullResponse));
|
||||
}
|
||||
} catch (e) {
|
||||
logError('$runtimeType::execute(): Exception = $e');
|
||||
yield Left(TryGuessingWebFingerFailure(exception: e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<OIDCResponse?> _checkOIDCAvailableFromOidcRequest(
|
||||
OIDCRequest oidcRequest,
|
||||
) async {
|
||||
try {
|
||||
return await _authenticationOIDCRepository.checkOIDCIsAvailable(
|
||||
oidcRequest,
|
||||
);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user