Authentication
Authentication
Asana CLI supports two authentication methods: Personal Access Tokens (PAT) and OAuth 2.0.
Personal Access Token (Recommended)
The quickest and simplest method for personal use and CLI tools.
Advantages
- Quick Setup: No OAuth configuration required
- Simple: Just one token to manage
- Perfect for CLI: Designed for personal automation
- No Expiration: Tokens don't expire (unless revoked)
Creating a Token
- Visit Asana Developer Console
- Click "Create New Token"
- Give it a descriptive name (e.g., "Asana CLI")
- Copy the generated token immediately (you won't see it again)
Login with Token
bun run dev auth login --token YOUR_TOKEN
Login with Default Workspace
Set a default workspace during login:
bun run dev auth login --token YOUR_TOKEN -w WORKSPACE_ID
This reduces the need to specify -w in every command.
Using Environment Variables
Store your token in an environment variable:
export ASANA_ACCESS_TOKEN=your_token_here
Then login without typing the token:
bun run dev auth login
OAuth 2.0
For multi-user applications, enhanced security, or when building apps for others.
Advantages
- Secure: User passwords never shared
- Scoped Access: Request only needed permissions
- Multi-User: Support multiple users in one app
- Revokable: Users can revoke access anytime
Creating OAuth Application
- Go to Asana Developer Console
- Click "Create New App"
- Fill in application details:
- App Name: Your application name
- Redirect URI:
http://localhost:8080/callback
- Copy Client ID and Client Secret
Configuration
Method 1: Environment Variables
export ASANA_CLIENT_ID=your_client_id
export ASANA_CLIENT_SECRET=your_client_secret
Method 2: .env File
Create .env file in project root:
cp .env.example .env
Edit .env:
ASANA_CLIENT_ID=your_client_id
ASANA_CLIENT_SECRET=your_client_secret
.env files - no additional configuration needed!Login with OAuth
bun run dev auth login
This will:
- Start a local server on port 8080
- Open your browser to Asana authorization page
- Receive the authorization code
- Exchange code for access/refresh tokens
- Store tokens securely
Token Refresh
OAuth tokens expire after a certain time. The CLI automatically refreshes them when needed.
You can also manually refresh:
bun run dev auth refresh
Managing Authentication
Check Current User
Verify who you're logged in as:
bun run dev auth whoami
Output includes:
- User name
- User email
- Workspace access
- Authentication method
Logout
Clear stored credentials:
bun run dev auth logout
This removes:
- Access tokens
- Refresh tokens
- Workspace settings
Switch Accounts
# Logout first
bun run dev auth logout
# Login with new credentials
bun run dev auth login --token NEW_TOKEN
Configuration File
Authentication data is stored in ~/.asana-cli/config.json:
{
"accessToken": "...",
"refreshToken": "...",
"authType": "oauth",
"workspace": "...",
"expiresAt": 1234567890
}
Manual Configuration
You can manually edit this file, but it's recommended to use the CLI commands instead.
Environment Variables
Supported environment variables:
# OAuth Configuration
ASANA_CLIENT_ID=your_client_id
ASANA_CLIENT_SECRET=your_client_secret
# Direct Token (PAT)
ASANA_ACCESS_TOKEN=your_token
# Default Workspace
ASANA_WORKSPACE=workspace_id
Security Best Practices
Recommendations
- Use PAT for Personal Use: Simpler and sufficient for single-user CLI
- Use OAuth for Apps: If building for others or need scoped permissions
- Rotate Tokens Regularly: Create new tokens periodically
- Use Environment Variables: Don't hardcode tokens in scripts
- Keep Tokens Secret: Never share or commit tokens
- Revoke Unused Tokens: Remove tokens you no longer need ::
Troubleshooting
Token Not Working
# Verify token is valid
bun run dev auth whoami
# If invalid, logout and login again
bun run dev auth logout
bun run dev auth login --token YOUR_TOKEN
OAuth Redirect Issues
Make sure redirect URI in Asana Developer Console exactly matches:
http://localhost:8080/callback
Port Already in Use
If port 8080 is busy, OAuth login will fail. Stop other services using that port.
Related
- Getting Started - Initial setup guide
- Configuration - Advanced configuration
- Task Management - Using the CLI