credential_manager 1.0.4+1 copy "credential_manager: ^1.0.4+1" to clipboard
credential_manager: ^1.0.4+1 copied to clipboard

PlatformAndroid

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 #

  1. Add proguard rules: Create or update android/app/proguard-rules.pro:

    -if class androidx.credentials.CredentialManager
    -keep class androidx.credentials.playservices.** {
      *;
    }
    
  2. Update android/app/build.gradle:

    android {
      buildTypes {
        release {
          minifyEnabled true
          proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
      }
    }
    

Usage in Flutter #

  1. Import the package:

    import 'package:credential_manager/credential_manager.dart';
    
  2. Create a CredentialManager instance:

    CredentialManager credentialManager = CredentialManager();
    
  3. Check if the platform is supported:

    if (credentialManager.isSupportedPlatform) {
      // Supported
    }
    
  4. Initialize the Credential Manager:

    await credentialManager.init(
      preferImmediatelyAvailableCredentials: true,
      googleClientId: googleClientId // Optional for Google Sign-In
    );
    
  5. Save credentials:

    await credentialManager.savePasswordCredentials(
      PasswordCredential(username: username, password: password)
    );
    
  6. Save Google credentials:

    final GoogleIdTokenCredential? gCredential = await credentialManager.saveGoogleCredential();
    

    For Google button flow:

    await credentialManager.saveGoogleCredential(useButtonFlow: true);
    
    Get Google/Password Saved Credential Get Google/Password Saved Credential Success
  7. Get saved credentials:

    Credentials credential = await credentialManager.getPasswordCredentials();
    
    Get Credential 1 Google Save Credential 1
  8. 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.

23
likes
160
points
979
downloads

Publisher

verified publishersmkwinner.live

Weekly Downloads

Credential Manager plugin,Help one-tap Login functionality and store credentials in Google service account of user.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

encrypt, flutter, plugin_platform_interface

More

Packages that depend on credential_manager