How to add auth to your Rust CLI using WorkOS
Blog post from WorkOS
Modern command-line interface (CLI) applications often require user authentication, and implementing a web-based OAuth flow is an efficient approach. This guide details how to incorporate a CLI login flow using WorkOS CLI Auth, utilizing the OAuth 2.0 Device Authorization Grant, which is particularly suitable for CLIs where embedding a browser is impractical. The process involves creating a Rust CLI that requests a device code from WorkOS, displays a user-friendly prompt with a verification URL and code, polls WorkOS while the user logs in, and exchanges the device code for tokens upon authorization. This method enhances security by enabling users to authenticate through the browser without needing to manually paste authentication tokens. The tutorial emphasizes the importance of displaying the user_code and verification_uri to users while keeping the device_code internal, and it provides step-by-step instructions on setting up the project with necessary dependencies and implementing the authentication flow.