xurl is a command-line tool that simplifies making authenticated requests to the X (formerly Twitter) API. It handles OAuth 2.0 authentication automatically and provides a curl-like interface for API interactions.
- OAuth 2.0 authentication with PKCE
- Token persistence for multiple users
- Automatic token refresh
- Support for all HTTP methods
- JSON request/response handling
- Custom header support
curl -fsSL https://raw.githubusercontent.com/santiagomed/xurl/main/install.sh | sudo bashBefore using xurl, you need to set up the following environment variables:
export CLIENT_ID="your_client_id"
export CLIENT_SECRET="your_client_secret"Optional environment variables (to override defaults):
export REDIRECT_URI="<your_redirect_uri>"
export AUTH_URL="<your_auth_url>"
export TOKEN_URL="<your_token_url>"Basic usage:
xurl '/2/users/me'To cache authentication for a specific user, use the -u option:
xurl -u santiagomedr '/2/users/me'POST request with data:
xurl -X POST -d '{"text":"Hello, World!"}' '/2/tweets'Adding custom headers:
xurl -H "Content-Type: application/json" '/2/users/me'The tool implements OAuth 2.0 with PKCE for secure authentication. When you make your first request:
- A browser window opens for X authentication
- After authorizing, you'll be redirected back to the local callback server
- The token is automatically saved for future use
src/auth/: OAuth implementation and token managementsrc/api/: API client and request handlingsrc/cli/: Command-line interface and argument parsingsrc/config/: Configuration managementsrc/errors/: Error handling
- OAuth authentication errors
- Network and HTTP errors
- API response errors
- Configuration errors
To run tests:
cargo testContributions are welcome!
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
Key dependencies include:
oauth2: OAuth 2.0 authenticationreqwest: HTTP clienttokio: Async runtimeaxum: Web server for OAuth callbackclap: Command line argument parsingserde: Serialization/deserialization
This project is open-sourced under the MIT License - see the LICENSE file for details.