A CLI tool that authenticates users via browser-based OAuth flow.
- Browser-based OAuth 2.0 authentication flow
- Automatic browser opening for seamless login experience
- Secure token storage in user's home directory
- Support for multiple OAuth providers (Google, GitHub, Auth0, etc.)
- CSRF protection with state parameter
- Token expiry checking
go install github.com/sredxny/device-flow-cli@latestOr build from source:
git clone https://github.com/sredxny/device-flow-cli.git
cd device-flow-cli
go build -o device-flow-cliCopy .env.example to .env and fill in your OAuth provider details:
cp .env.example .envThen edit .env with your OAuth configuration:
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret
OAUTH_AUTH_URL=https://accounts.google.com/o/oauth2/v2/auth
OAUTH_TOKEN_URL=https://oauth2.googleapis.com/token
You can also provide configuration via command-line flags:
device-flow-cli login \
--client-id YOUR_CLIENT_ID \
--client-secret YOUR_CLIENT_SECRET \
--auth-url https://accounts.google.com/o/oauth2/v2/auth \
--token-url https://oauth2.googleapis.com/tokenAuthenticate by opening a browser window:
device-flow-cli loginThis will:
- Start a local callback server on port 8080
- Open your default browser to the OAuth provider's login page
- Wait for you to complete authentication
- Receive the callback and store the access token securely
Check if you're currently authenticated:
device-flow-cli statusClear stored credentials:
device-flow-cli logoutYou need to register your application with an OAuth provider. Here are common examples:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the relevant APIs
- Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client ID"
- Select "Desktop app" as application type
- Add
http://localhost:8080/callbackas authorized redirect URI
Configuration:
OAUTH_AUTH_URL=https://accounts.google.com/o/oauth2/v2/auth
OAUTH_TOKEN_URL=https://oauth2.googleapis.com/token
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click "New OAuth App"
- Set Homepage URL to your repo
- Set Authorization callback URL to
http://localhost:8080/callback
Configuration:
OAUTH_AUTH_URL=https://github.com/login/oauth/authorize
OAUTH_TOKEN_URL=https://github.com/login/oauth/access_token
- Go to your Auth0 Dashboard
- Create a new Application (Native type)
- Add
http://localhost:8080/callbackto Allowed Callback URLs
Configuration:
OAUTH_AUTH_URL=https://YOUR_DOMAIN.auth0.com/authorize
OAUTH_TOKEN_URL=https://YOUR_DOMAIN.auth0.com/oauth/token
- Tokens are stored in
~/.device-flow-cli/token.jsonwith restricted permissions (0600) - CSRF protection using state parameter
- Automatic token expiry checking
- Local callback server only binds to localhost
go build -o device-flow-cligo test ./...MIT