auth_api_rest_web 3.0.0
auth_api_rest_web: ^3.0.0 copied to clipboard
Flutter package for OAuth2 authentication with session management, OTP validation, password recovery, and user registration. Web platform only. Uses BLoC pattern.
auth_api_rest_web #
Flutter package for OAuth2 authentication with session management, OTP validation, password recovery, and user registration. Web platform only.
Features #
- OAuth2 authentication with Authorization Code Grant flow
- Session management with multiple active sessions support
- OTP (Two-Factor Authentication) with Google Authenticator integration
- Password recovery flow (3-step process)
- User registration support
- BLoC pattern implementation for state management
- Real-time socket integration for session synchronization
- Debug logging with configurable levels
Installation #
Add this to your pubspec.yaml:
dependencies:
auth_api_rest_web: ^1.0.1
Usage #
1. Initialize in main.dart #
import 'package:auth_api_rest_web/auth_api_rest_web.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_models_provider/global/environment.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final authApiRest = AuthApiRest(
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
redirectUri: RedirectUri.loginPost,
gestorData: GestorData.objectBox,
coleccionFuncionesBackend: '',
);
await authApiRest.init(
endpointApi: 'https://api.yourserver.com',
endpointAuth: 'https://auth.yourserver.com',
endpointSocket: 'https://socket.yourserver.com',
);
runApp(MyApp(authApiRest: authApiRest));
}
class MyApp extends StatelessWidget {
const MyApp({super.key, required this.authApiRest});
final AuthApiRest authApiRest;
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [...authApiRest.lstBlocsAuth],
child: MaterialApp(
title: 'My App',
home: LoginPage(),
),
);
}
}
2. Login #
context.read<AuthBloc>().add(OnLoginAuthV4(
usuario: email,
password: password,
));
3. Listen to Auth State #
BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state.isLoggedIn && !state.isWorking) {
// Login successful
}
if (state.error.isNotEmpty && !state.isWorking) {
// Handle error
}
},
child: // ...
)
4. Logout #
context.read<AuthBloc>().add(const OnLogoutAuth());
Available Events #
| Event | Description |
|---|---|
OnLoginAuthV4 |
Login with username/password |
OnLogoutAuth |
Logout current session |
OnObtieneSesionesActivasAuth |
Get active sessions list |
OnCerrarSesionActivaAuth |
Close a specific session |
OnGeneraOTPAuth |
Generate OTP QR code |
OnValidaOTPAuth |
Validate OTP code |
OnInicioRegistroNuevoAuth |
Start registration process |
OnFinRegistroNuevoAuth |
Complete registration |
OnOlvideMiPasswordPaso1Auth |
Password reset step 1 (email) |
OnOlvideMiPasswordPaso2Auth |
Password reset step 2 (code) |
OnOlvideMiPasswordPaso3Auth |
Password reset step 3 (new password) |
Platform Support #
| Platform | Supported |
|---|---|
| Web | Yes |
| Android | No |
| iOS | No |
| macOS | No |
| Linux | No |
| Windows | No |
License #
MIT License - see LICENSE for details.
Author #
RobleSistemas