credential_manager 1.0.4+1 credential_manager: ^1.0.4+1 copied to clipboard
Credential Manager plugin,Help one-tap Login functionality and store credentials in Google service account of user.
Credential Manager #
Credential Manager is a Jetpack API that supports multiple sign-in methods, such as username and password, passkeys, and federated sign-in solutions (like Sign-in with Google) in a single API, simplifying integration for developers.
For users, Credential Manager unifies the sign-in interface across authentication methods, making it clearer and easier to sign into apps, regardless of the chosen method.
Note: This package is currently only supported for Android.
Getting Started #
Add the dependency to your pubspec.yaml file:
credential_manager: <latest_version>
Or run:
flutter pub add credential_manager
Setup Android #
-
Add proguard rules: Create or update
android/app/proguard-rules.pro
:-if class androidx.credentials.CredentialManager -keep class androidx.credentials.playservices.** { *; }
-
Update
android/app/build.gradle
:android { buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }
Usage in Flutter #
-
Import the package:
import 'package:credential_manager/credential_manager.dart';
-
Create a
CredentialManager
instance:CredentialManager credentialManager = CredentialManager();
-
Check if the platform is supported:
if (credentialManager.isSupportedPlatform) { // Supported }
-
Initialize the Credential Manager:
await credentialManager.init( preferImmediatelyAvailableCredentials: true, googleClientId: googleClientId // Optional for Google Sign-In );
-
Save credentials:
await credentialManager.savePasswordCredentials( PasswordCredential(username: username, password: password) );
-
Save Google credentials:
final GoogleIdTokenCredential? gCredential = await credentialManager.saveGoogleCredential();
For Google button flow:
await credentialManager.saveGoogleCredential(useButtonFlow: true);
-
Get saved credentials:
Credentials credential = await credentialManager.getPasswordCredentials();
-
Logout:
await credentialManager.logout();
Encrypt Your Credentials #
To enhance security, you can encrypt the password field:
Encrypt Your Credentials #
To enhance security, you can encrypt the password field:
dart
final secretKey = "<Secret-key>"; // 16-character string
final ivKey = "<16-bit-iv-key>";
// Save encrypted credentials
await credentialManager.saveEncryptedCredentials(
credential: PasswordCredential(username: username, password: password),
secretKey: secretKey,
ivKey: ivKey
);
// Get and decrypt credentials
Credentials credential = await credentialManager.getEncryptedCredentials(
secretKey: secretKey,
ivKey: ivKey
);
Additional Setup #
Error Handling #
For detailed error codes and messages, see Error Handler.
Properties and Methods #
For a complete list of properties and methods, see Properties and Methods.
Upcoming Features #
- iOS Support
Contributing #
Contributions are welcome! Please see the Contributing Guidelines for more details.
If you find this package useful, please:
- Star it on GitHub
- Tweet about it
- Mention it in your blog posts
For bug reports, feature requests, or questions, please open an issue on GitHub.