# Password Generator API Integration Guide This guide provides comprehensive examples for integrating the Password Generator API with popular password managers, launchers, and automation tools. ## Table of Contents - [Quick Start](#quick-start) - [Password Managers](#password-managers) - [Launchers & Tools](#launchers--tools) - [Automation Scripts](#automation-scripts) - [Security Considerations](#security-considerations) ## Quick Start The API provides several endpoints for password generation: **Base URL:** `http://localhost:8080/api/v1` **Generate Password:** ```bash curl -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d '{"type":"diceware","count":1,"options":{"words":6}}' ``` ## Password Managers ### Bitwarden #### Bitwarden CLI Integration **Installation:** ```bash npm install -g @bitwarden/cli ``` **Basic Password Generation and Storage:** ```bash #!/bin/bash # generate-and-store-bitwarden.sh # Login to Bitwarden (do this once) bw login # Unlock vault (enter master password when prompted) export BW_SESSION="$(bw unlock --raw)" # Generate high-entropy password PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d '{"type":"high-entropy","count":1,"options":{"length":20,"includeSymbols":true}}' | \ jq -r '.data.passwords[0]') # Create new login item ITEM_DATA=$(cat < ['name' => 'High Entropy', 'icon' => '🔒', 'options' => '{"length":16}'], 'diceware' => ['name' => 'Diceware', 'icon' => '🎲', 'options' => '{"words":5}'], 'passkey' => ['name' => 'Passkey', 'icon' => '🗝️', 'options' => '{"syllables":3}'], 'xkcdpass' => ['name' => 'XKCD', 'icon' => '💭', 'options' => '{"words":4}'] ]; $items = []; foreach ($types as $type => $config) { $items[] = [ 'uid' => $type, 'title' => $config['name'] . ' Password', 'subtitle' => 'Generate ' . strtolower($config['name']) . ' password', 'arg' => $type, 'icon' => ['emoji' => $config['icon']] ]; } echo json_encode(['items' => $items]); ?> ``` **alfred-generate.sh:** ```bash #!/bin/bash TYPE=$1 case $TYPE in "high-entropy") OPTIONS='{"length":16,"includeSymbols":true}' ;; "diceware") OPTIONS='{"words":5,"capitalize":true}' ;; "passkey") OPTIONS='{"syllables":3,"addNumbers":true}' ;; "xkcdpass") OPTIONS='{"words":4,"capitalize":true,"addNumber":true}' ;; esac PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d "{\"type\":\"$TYPE\",\"count\":1,\"options\":$OPTIONS}" | \ jq -r '.data.passwords[0]') echo "$PASSWORD" | pbcopy echo "$PASSWORD" ``` ### LaunchBar #### LaunchBar Action **PasswordGenerator.lbaction/Contents/Scripts/default.sh:** ```bash #!/bin/bash PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d '{"type":"passkey","count":1,"options":{"syllables":4,"addNumbers":true}}' | \ jq -r '.data.passwords[0]') if [ -n "$PASSWORD" ]; then echo "$PASSWORD" | pbcopy echo "$PASSWORD" else echo "Error generating password" exit 1 fi ``` ### Ubar / Menu Bar Apps #### BitBar Plugin **password-generator.1m.sh:** ```bash #!/bin/bash echo "🔐 Password Generator" echo "---" # Generate different types TYPES=("high-entropy:High Entropy" "diceware:Diceware" "passkey:Passkey" "xkcdpass:XKCD") for TYPE_PAIR in "${TYPES[@]}"; do TYPE="${TYPE_PAIR%%:*}" NAME="${TYPE_PAIR##*:}" PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d "{\"type\":\"$TYPE\",\"count\":1}" | \ jq -r '.data.passwords[0]' 2>/dev/null) if [ -n "$PASSWORD" ]; then echo "$NAME: $PASSWORD | bash='echo \"$PASSWORD\" | pbcopy' terminal=false" fi done echo "---" echo "API Status | bash='curl -s http://localhost:8080/api/v1/health' terminal=true" ``` ## Automation Scripts ### Automated Password Rotation ```bash #!/bin/bash # rotate-passwords.sh SERVICES=("email:user@example.com" "bank:john.doe" "social:johndoe123") for SERVICE_PAIR in "${SERVICES[@]}"; do SERVICE="${SERVICE_PAIR%%:*}" USERNAME="${SERVICE_PAIR##*:}" # Generate new password PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d '{"type":"high-entropy","count":1,"options":{"length":20}}' | \ jq -r '.data.passwords[0]') # Update in password manager (example with Bitwarden) ITEM_ID=$(bw list items --search "$SERVICE" | jq -r '.[0].id') if [ "$ITEM_ID" != "null" ]; then ITEM=$(bw get item "$ITEM_ID") UPDATED_ITEM=$(echo "$ITEM" | jq ".login.password = \"$PASSWORD\"") echo "$UPDATED_ITEM" | bw encode | bw edit item "$ITEM_ID" echo "Rotated password for $SERVICE: $PASSWORD" fi done ``` ### Bulk Password Generation for Teams ```bash #!/bin/bash # team-password-generator.sh TEAM_MEMBERS=("alice" "bob" "charlie" "diana") SERVICES=("staging" "development" "testing") for MEMBER in "${TEAM_MEMBERS[@]}"; do echo "Generating passwords for $MEMBER:" for SERVICE in "${SERVICES[@]}"; do PASSWORD=$(curl -s -X POST http://localhost:8080/api/v1/passwords/generate \ -H "Content-Type: application/json" \ -d '{"type":"diceware","count":1,"options":{"words":4,"addNumber":true}}' | \ jq -r '.data.passwords[0]') # Store in team password manager op item create \ --category=login \ --title="$SERVICE-$MEMBER" \ --field="username=$MEMBER" \ --field="password=$PASSWORD" \ --vault="Team Vault" echo " $SERVICE: $PASSWORD" done echo "" done ``` ## Security Considerations ### API Security 1. **Local Deployment**: Run the API locally or on a secure internal network 2. **Rate Limiting**: The API includes built-in rate limiting (60 requests/minute by default) 3. **No Logging of Passwords**: Passwords are not logged in server logs 4. **HTTPS**: Use HTTPS in production deployments ### Integration Security 1. **Environment Variables**: Store API endpoints in environment variables: ```bash export PASSWORD_API_URL="https://passwords.internal.company.com/api/v1" ``` 2. **Script Permissions**: Set appropriate permissions on scripts: ```bash chmod 700 password-scripts/ chmod 600 password-scripts/*.sh ``` 3. **Secure Storage**: Ensure integration scripts don't leave passwords in temporary files: ```bash # Good: Use pipes and variables PASSWORD=$(curl -s ... | jq -r '.data.passwords[0]') # Bad: Don't write to temporary files # curl -s ... > /tmp/password.json ``` ### Production Deployment For production use, consider: 1. **Authentication**: Add API key authentication 2. **Network Security**: Deploy behind a firewall or VPN 3. **Monitoring**: Monitor API usage and failed requests 4. **Backup**: Regular backups of configuration and logs ### Password Manager Sync When integrating with password managers: 1. **Verify Storage**: Always verify passwords are correctly stored 2. **Error Handling**: Implement proper error handling for API failures 3. **Rollback**: Have procedures to rollback failed password updates 4. **Audit Trail**: Maintain logs of password generation and updates ## Troubleshooting ### Common Issues **API Connection Issues:** ```bash # Test API connectivity curl -s http://localhost:8080/api/v1/health # Check if service is running netstat -tlnp | grep 8080 ``` **JSON Parsing Issues:** ```bash # Validate JSON response curl -s http://localhost:8080/api/v1/passwords | jq '.' # Check for errors curl -s http://localhost:8080/api/v1/passwords | jq '.error' ``` **Password Manager Integration:** ```bash # Test CLI tools separately bw --version op --version keepassxc-cli --version # Verify authentication bw status op whoami ``` This integration guide provides comprehensive examples for connecting the Password Generator API with popular tools and services. Adapt these examples based on your specific requirements and security policies.