Password saving
Save credentials to system keychain securely π
The Capacitor Autofill Save Password plugin provides password saving and autofill functionality for Capacitor applications. This plugin integrates with system-level credential management to offer seamless authentication experiences with secure password storage and retrieval.
Password saving
Save credentials to system keychain securely π
Autofill integration
System-level password autofill support ποΈ
Cross-platform
iOS support with Android development in progress π±
Domain association
Associated domains for seamless authentication β€οΈ
npm install @capgo/capacitor-autofill-save-passwordnpx cap sync
Configure associated domains in your Apple Developer account and add them to your App.entitlements
file:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>com.apple.developer.associated-domains</key> <array> <string>webcredentials:yourdomain.com</string> <string>webcredentials:www.yourdomain.com</string> </array></dict></plist>
Add a .well-known/apple-app-site-association
file to your website:
{ "webcredentials": { "apps": [ "TEAMID.com.yourcompany.yourapp" ] }}
promptDialog(options)
- Save password to system keychainreadPassword()
- Read saved password from keychainimport { SavePassword } from '@capgo/capacitor-autofill-save-password';
// Save password after successful loginasync function login(username: string, password: string) { try { // Perform your login logic here const loginSuccess = await performLogin(username, password);
if (loginSuccess) { // Prompt user to save password await SavePassword.promptDialog({ username: username, password: password, url: 'https://yourdomain.com' // iOS only });
console.log('Password saved successfully'); } } catch (error) { console.error('Failed to save password:', error); }}
// Read saved password for autofillasync function loadSavedCredentials() { try { const credentials = await SavePassword.readPassword();
if (credentials.username && credentials.password) { console.log('Found saved credentials'); // Pre-fill login form return { username: credentials.username, password: credentials.password }; } } catch (error) { console.error('Failed to read saved password:', error); }
return null;}
For future Android support, the following configuration will be required:
Add to android/app/build.gradle
:
apply plugin: 'com.google.gms.google-services'
Add to android/app/src/main/res/values/strings.xml
:
<resources> <string name="asset_statements"> [{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "web", "site": "https://yourdomain.com" } }] </string></resources>
Add google-services.json
to your Android project.
Saves user credentials to the system keychain.
interface SavePasswordOptions { username: string; password: string; url?: string; // iOS only - associated domain URL}
Retrieves saved credentials from the system keychain.
interface SavedCredentials { username: string; password: string;}
import { SavePassword } from '@capgo/capacitor-autofill-save-password';
class AuthService { async login(username: string, password: string) { try { // Authenticate with your backend const response = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) });
if (response.ok) { // Offer to save credentials await this.offerToSavePassword(username, password); return true; } } catch (error) { console.error('Login failed:', error); } return false; }
private async offerToSavePassword(username: string, password: string) { try { await SavePassword.promptDialog({ username, password, url: 'https://yourdomain.com' }); } catch (error) { // User declined to save or error occurred console.log('Password not saved:', error); } }
async loadSavedCredentials() { try { return await SavePassword.readPassword(); } catch (error) { console.log('No saved credentials found'); return null; } }}
Check the complete documentation for detailed implementation guides and advanced integration patterns.