Commencer
Installation
Section titled “Installation”npm install @capgo/capacitor-autofill-save-passwordnpx cap syncyarn add @capgo/capacitor-autofill-save-passwordnpx cap syncpnpm add @capgo/capacitor-autofill-save-passwordnpx cap syncbun add @capgo/capacitor-autofill-save-passwordnpx cap syncPlatform Support
Section titled “Platform Support”- iOS: Full Support (iOS 18.3 and older versions)
- Android: Work in progress
Platform Configuration
Section titled “Platform Configuration”1. Associated Domains Configuration
Section titled “1. Associated Domains Configuration”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>2. Web Credential Configuration
Section titled “2. Web Credential Configuration”Add a .well-known/apple-app-site-association file to your website:
{ "webcredentials": { "apps": [ "TEAMID.com.yourcompany.yourapp" ] }}Android (Future Support)
Section titled “Android (Future Support)”1. Google Services Plugin
Section titled “1. Google Services Plugin”Add to android/app/build.gradle:
apply plugin: 'com.google.gms.google-services'2. Domain Configuration
Section titled “2. Domain Configuration”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>Utilisation Exemple
Section titled “Utilisation Exemple”import { 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;}API Référence
Section titled “API Référence”promptDialog(Options)
Section titled “promptDialog(Options)”promptDialog(options: SavePasswordOptions) => Promise<void>Saves Utilisateur credentials to the system keychain.
| Param | Type |
|---|---|
options | SavePasswordOptions |
readPassword()
Section titled “readPassword()”readPassword() => Promise<SavedCredentials>Retrieves saved credentials from the system keychain.
Returns: Promise<SavedCredentials>
Interfaces
Section titled “Interfaces”SavePasswordOptions
Section titled “SavePasswordOptions”| Prop | Type | Description |
|---|---|---|
username | string | The username to save |
password | string | The password to save |
url | string | iOS only - associated domain URL (optional) |
SavedCredentials
Section titled “SavedCredentials”| Prop | Type | Description |
|---|---|---|
username | string | The saved username |
password | string | The saved password |
Integration with Connexion Flow
Section titled “Integration with Connexion Flow”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; } }}Best Practices
Section titled “Best Practices”- Only prompt to Enregistrer passwords after successful authentication
- Handle cases where Utilisateurs decline to Enregistrer passwords gracefully
- Implement proper Erreur handling for keychain access failures
- Use associated domains for seamless web-Application credential sharing
- Test autofill functionality across different iOS versions
Sécurité Considerations
Section titled “Sécurité Considerations”- Credentials are stored in the system keychain with appropriate Sécurité flags
- Associated domains ensure credentials are only accessible to authorized apps
- Follow platform Sécurité guidelines for credential management
- Consider implementing additional Sécurité measures for sensitive applications