- Swift 56.9%
- Go 40.6%
- Shell 2.5%
| BlinkMobile | ||
| build | ||
| .blink_auth.json | ||
| .gitignore | ||
| auth.go | ||
| build.sh | ||
| CHANGELOG.md | ||
| client.go | ||
| config.go | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| password.go | ||
| pkce.go | ||
| README.md | ||
| USAGE_EXAMPLES.md | ||
Blink CLI
A command-line interface for controlling Blink cameras using the official Blink API.
Features
- OAuth2 authentication with PKCE flow
- Two-factor authentication (2FA) support via SMS
- Secure password input (hidden as you type)
- Login and credential management
- List networks and cameras
- Arm/disarm networks
- Take camera snapshots and video clips
- List recent video clips
- Download video clips to local files
- Live video streaming (liveview sessions)
- Secure credential storage
Installation
Prerequisites
- Go 1.21 or higher
Build from source
# Clone or navigate to the project directory
cd blink-cli
# Download dependencies
go mod download
# Build the binary
go build -o blink-cli .
# Optional: Install globally
go install
Usage
Authentication
First, authenticate with your Blink account:
./blink-cli login -e your-email@example.com
You will be prompted to enter your password securely (the password won't be visible as you type).
If your account has two-factor authentication (2FA) enabled, you will also be prompted to enter the verification code sent to your phone via SMS.
Credentials are securely stored in .blink_auth.json in the same directory as the binary, with file permissions 0600.
Check authentication status
./blink-cli status
List networks
./blink-cli networks
List cameras
List all cameras:
./blink-cli cameras
List cameras for a specific network:
./blink-cli cameras -n 123456
Arm/Disarm networks
Arm a network:
./blink-cli arm 123456
Disarm a network:
./blink-cli disarm 123456
Take and view snapshots
Request a new snapshot from a camera:
./blink-cli snapshot 159845
View the latest snapshot (downloads and opens in your default image viewer):
./blink-cli view-snapshot 159845
Download the latest snapshot to a file:
./blink-cli download-snapshot 159845 my-snapshot.jpg
Record and download video clips
Request a video clip from a camera:
./blink-cli clip 159845
List recent video clips:
./blink-cli list-media
# Limit to 5 most recent
./blink-cli list-media -l 5
Download a video clip:
./blink-cli download 6978624548 my-clip.mp4
Play the most recent clip (downloads and opens in your default video player):
./blink-cli play
Start a liveview session
Start a live video stream from a camera and open in VLC:
./blink-cli liveview 159845 --open
Or just get the stream URL:
./blink-cli liveview 159845
The command automatically converts Blink's immis:// protocol to standard RTSP format and can open it directly in VLC. The stream will remain active for 90 minutes (5400 seconds).
How it works
This CLI implements the Blink OAuth2 authentication flow with PKCE (Proof Key for Code Exchange):
- Authorization Request: Initiates OAuth flow with code challenge
- Sign In: Submits credentials with CSRF protection
- Authorization Code: Retrieves authorization code from redirect
- Token Exchange: Exchanges code for access and refresh tokens using code verifier
The authentication follows the exact flow captured from the official Blink iOS app, ensuring compatibility with Blink's security requirements.
API Endpoints
- OAuth Base:
https://api.oauth.blink.com - API Base:
https://rest-prod.immedia-semi.com
Security Features
- PKCE flow for secure OAuth authentication
- CSRF token validation
- Secure credential storage with restricted file permissions
- Hardware ID generation for device identification
- Cookie-based session management
Project Structure
.
├── main.go # CLI commands and application entry point
├── auth.go # OAuth authentication implementation
├── client.go # Blink API client for camera operations
├── config.go # Configuration and credential storage
├── pkce.go # PKCE challenge generation
├── password.go # Secure password input handling
├── go.mod # Go module dependencies
└── README.md # This file
Commands Reference
| Command | Description | Example |
|---|---|---|
login |
Authenticate with Blink account | blink-cli login -e email |
status |
Check authentication status | blink-cli status |
networks |
List all networks | blink-cli networks |
cameras |
List cameras (optionally by network) | blink-cli cameras -n 123 |
arm |
Arm a network | blink-cli arm 123456 |
disarm |
Disarm a network | blink-cli disarm 123456 |
snapshot |
Request camera snapshot | blink-cli snapshot 159845 |
view-snapshot |
View latest snapshot from camera | blink-cli view-snapshot 159845 |
download-snapshot |
Download snapshot to file | blink-cli download-snapshot 159845 snap.jpg |
clip |
Request video clip from camera | blink-cli clip 159845 |
list-media |
List recent video clips | blink-cli list-media -l 10 |
download |
Download a video clip | blink-cli download 6978624548 clip.mp4 |
play |
Download and play most recent clip | blink-cli play |
liveview |
Start liveview session | blink-cli liveview 159845 |
version |
Print version information | blink-cli version |
Development
The implementation is based on HAR file analysis of the official Blink app's API calls, ensuring:
- Correct OAuth flow sequence
- Proper header values and user agent strings
- Compatible device information
- Correct API endpoint usage
Troubleshooting
Authentication fails
- Verify your email and password are correct
- If you have 2FA enabled, make sure to enter the verification code when prompted
- Ensure you have an active internet connection
- Check that you can receive SMS messages if 2FA is enabled
Command returns "not authenticated"
Run the login command again:
./blink-cli login -e your-email@example.com -p your-password
Token expired
The access token expires after 4 hours (14400 seconds). Re-run the login command to get a fresh token.
License
MIT License - See LICENSE file for details
Disclaimer
This is an unofficial CLI tool and is not affiliated with or endorsed by Blink or Amazon. Use at your own risk.