feat(mobile): Implement Keycloak WebView authentication with HTTP callback

- Replace flutter_appauth with custom WebView implementation to resolve deep link issues
- Add KeycloakWebViewAuthService with integrated WebView for seamless authentication
- Configure Android manifest for HTTP cleartext traffic support
- Add network security config for development environment (192.168.1.11)
- Update Keycloak client to use HTTP callback endpoint (http://192.168.1.11:8080/auth/callback)
- Remove obsolete keycloak_auth_service.dart and temporary scripts
- Clean up dependencies and regenerate injection configuration
- Tested successfully on multiple Android devices (Xiaomi 2201116TG, SM A725F)

BREAKING CHANGE: Authentication flow now uses WebView instead of external browser
- Users will see Keycloak login page within the app instead of browser redirect
- Resolves ERR_CLEARTEXT_NOT_PERMITTED and deep link state management issues
- Maintains full OIDC compliance with PKCE flow and secure token storage

Technical improvements:
- WebView with custom navigation delegate for callback handling
- Automatic token extraction and user info parsing from JWT
- Proper error handling and user feedback
- Consistent authentication state management across app lifecycle
This commit is contained in:
DahoudG
2025-09-15 01:44:16 +00:00
parent 73459b3092
commit f89f6167cc
290 changed files with 34563 additions and 3528 deletions

View File

@@ -4,6 +4,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../core/di/injection.dart';
import '../../../../core/models/membre_model.dart';
import '../../../../core/error/error_handler.dart';
import '../../../../core/validation/form_validator.dart';
import '../../../../core/feedback/user_feedback.dart';
import '../../../../core/animations/loading_animations.dart';
import '../../../../core/animations/page_transitions.dart';
import '../../../../shared/theme/app_theme.dart';
import '../../../../shared/widgets/custom_text_field.dart';
import '../../../../shared/widgets/buttons/buttons.dart';
@@ -92,28 +97,41 @@ class _MembreCreatePageState extends State<MembreCreatePage>
body: BlocConsumer<MembresBloc, MembresState>(
listener: (context, state) {
if (state is MembreCreated) {
// Fermer l'indicateur de chargement
UserFeedback.hideLoading(context);
setState(() {
_isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Membre créé avec succès !'),
backgroundColor: AppTheme.successColor,
),
// Afficher le message de succès avec feedback haptique
UserFeedback.showSuccess(
context,
'Membre créé avec succès !',
onAction: () => Navigator.of(context).pop(true),
actionLabel: 'Voir la liste',
);
Navigator.of(context).pop(true); // Retourner true pour indiquer le succès
// Retourner à la liste après un délai
Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
Navigator.of(context).pop(true);
}
});
} else if (state is MembresError) {
// Fermer l'indicateur de chargement
UserFeedback.hideLoading(context);
setState(() {
_isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
backgroundColor: AppTheme.errorColor,
),
// Gérer l'erreur avec le nouveau système
ErrorHandler.handleError(
context,
state.failure,
onRetry: () => _submitForm(),
);
}
},
@@ -780,82 +798,122 @@ class _MembreCreatePageState extends State<MembreCreatePage>
}
bool _validatePersonalInfo() {
bool isValid = true;
final errors = <String>[];
if (_prenomController.text.trim().isEmpty) {
_showFieldError('Le prénom est requis');
isValid = false;
// Validation du prénom
final prenomError = FormValidator.name(_prenomController.text, fieldName: 'Le prénom');
if (prenomError != null) errors.add(prenomError);
// Validation du nom
final nomError = FormValidator.name(_nomController.text, fieldName: 'Le nom');
if (nomError != null) errors.add(nomError);
// Validation de la date de naissance
if (_dateNaissance != null) {
final dateError = FormValidator.birthDate(_dateNaissance!, minAge: 16);
if (dateError != null) errors.add(dateError);
}
if (_nomController.text.trim().isEmpty) {
_showFieldError('Le nom est requis');
isValid = false;
if (errors.isNotEmpty) {
UserFeedback.showWarning(context, errors.first);
return false;
}
return isValid;
return true;
}
bool _validateContactInfo() {
bool isValid = true;
final errors = <String>[];
if (_emailController.text.trim().isEmpty) {
_showFieldError('L\'email est requis');
isValid = false;
} else if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(_emailController.text)) {
_showFieldError('Format d\'email invalide');
isValid = false;
// Validation de l'email
final emailError = FormValidator.email(_emailController.text);
if (emailError != null) errors.add(emailError);
// Validation du téléphone
final phoneError = FormValidator.phone(_telephoneController.text);
if (phoneError != null) errors.add(phoneError);
// Validation de l'adresse (optionnelle)
final addressError = FormValidator.address(_adresseController.text);
if (addressError != null) errors.add(addressError);
// Validation de la profession (optionnelle)
final professionError = FormValidator.profession(_professionController.text);
if (professionError != null) errors.add(professionError);
if (errors.isNotEmpty) {
UserFeedback.showWarning(context, errors.first);
return false;
}
if (_telephoneController.text.trim().isEmpty) {
_showFieldError('Le téléphone est requis');
isValid = false;
}
return isValid;
return true;
}
void _showFieldError(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: AppTheme.errorColor,
duration: const Duration(seconds: 2),
),
);
}
void _submitForm() {
if (!_formKey.currentState!.validate()) {
// Validation finale complète
if (!_validateAllSteps()) {
return;
}
if (!_formKey.currentState!.validate()) {
UserFeedback.showWarning(context, 'Veuillez corriger les erreurs dans le formulaire');
return;
}
// Afficher l'indicateur de chargement
UserFeedback.showLoading(context, message: 'Création du membre en cours...');
setState(() {
_isLoading = true;
});
// Créer le modèle membre
final membre = MembreModel(
id: '', // Sera généré par le backend
numeroMembre: _numeroMembreController.text.trim(),
nom: _nomController.text.trim(),
prenom: _prenomController.text.trim(),
email: _emailController.text.trim(),
telephone: _telephoneController.text.trim(),
dateNaissance: _dateNaissance,
adresse: _adresseController.text.trim().isNotEmpty ? _adresseController.text.trim() : null,
ville: _villeController.text.trim().isNotEmpty ? _villeController.text.trim() : null,
codePostal: _codePostalController.text.trim().isNotEmpty ? _codePostalController.text.trim() : null,
pays: _paysController.text.trim().isNotEmpty ? _paysController.text.trim() : null,
profession: _professionController.text.trim().isNotEmpty ? _professionController.text.trim() : null,
dateAdhesion: _dateAdhesion,
actif: _actif,
statut: 'ACTIF',
version: 1,
dateCreation: DateTime.now(),
);
try {
// Créer le modèle membre avec validation des données
final membre = MembreModel(
id: '', // Sera généré par le backend
numeroMembre: _numeroMembreController.text.trim(),
nom: _nomController.text.trim(),
prenom: _prenomController.text.trim(),
email: _emailController.text.trim(),
telephone: _telephoneController.text.trim(),
dateNaissance: _dateNaissance,
adresse: _adresseController.text.trim().isNotEmpty ? _adresseController.text.trim() : null,
ville: _villeController.text.trim().isNotEmpty ? _villeController.text.trim() : null,
codePostal: _codePostalController.text.trim().isNotEmpty ? _codePostalController.text.trim() : null,
pays: _paysController.text.trim().isNotEmpty ? _paysController.text.trim() : null,
profession: _professionController.text.trim().isNotEmpty ? _professionController.text.trim() : null,
dateAdhesion: _dateAdhesion,
actif: _actif,
statut: 'ACTIF',
version: 1,
dateCreation: DateTime.now(),
);
// Envoyer l'événement de création
_membresBloc.add(CreateMembre(membre));
// Envoyer l'événement de création
_membresBloc.add(CreateMembre(membre));
} catch (e) {
UserFeedback.hideLoading(context);
ErrorHandler.handleError(context, e, customMessage: 'Erreur lors de la préparation des données');
setState(() {
_isLoading = false;
});
}
}
bool _validateAllSteps() {
// Valider toutes les étapes
if (!_validatePersonalInfo()) return false;
if (!_validateContactInfo()) return false;
// Validation supplémentaire pour les champs obligatoires
if (_dateNaissance == null) {
UserFeedback.showWarning(context, 'La date de naissance est requise');
return false;
}
return true;
}
Future<void> _selectDateNaissance() async {