flutter_secure_auth 0.1.5
flutter_secure_auth: ^0.1.5 copied to clipboard
A secure, lightweight authentication package for Flutter (REST + OAuth2 PKCE + token refresh) with secure local storage.
flutter_secure_auth π #
A secure, lightweight, and null-safe authentication package for Flutter.
It supports:
- π OAuth2 PKCE Authorization Code flow
- π Access/Refresh token handling
- π§ Auto token refresh
- πΎ Secure token storage (Keychain / Keystore)
- β‘ Easy REST integration
Designed for developers who want security + simplicity when integrating login systems in Flutter apps.
π Installation #
Add this to your pubspec.yaml:
dependencies:
flutter_secure_auth: ^0.1.0
π§© Usage
#Initialize
final authService = AuthService(
tokenEndpoint: Uri.parse('https://api.example.com/oauth/token'),
revokeEndpoint: Uri.parse('https://api.example.com/oauth/revoke'),
);
#πΈ Sign in with username/password
final tokens = await authService.signInWithPassword(
endpoint: Uri.parse('https://api.example.com/auth/login'),
username: 'user@example.com',
password: 'securePassword',
);
#πΈ OAuth2 PKCE Flow
final pkce = createPkcePair();
final authUrl = Uri.parse('https://auth.example.com/authorize').replace(queryParameters: {
'response_type': 'code',
'client_id': 'your-client-id',
'redirect_uri': 'com.example.app:/oauthredirect',
'scope': 'openid profile offline_access',
'code_challenge': pkce.codeChallenge,
'code_challenge_method': 'S256',
'state': pkce.state,
});
// After redirect and code received:
final tokens = await authService.exchangeAuthorizationCode(
code: 'returned-code',
codeVerifier: pkce.codeVerifier,
redirectUri: Uri.parse('com.example.app:/oauthredirect'),
);
#πΈ Make authorized requests
final request = http.Request('GET', Uri.parse('https://api.example.com/user'));
final authed = await authService.authorizedRequest(request);
final response = await authed.send();
#πΈ Sign out
await authService.signOut();