feat: enhance login command with direct user login support#40
feat: enhance login command with direct user login support#40victorvhs017 merged 5 commits intomainfrom
Conversation
… configuration - Introduced flags for email, password, and hosting to facilitate direct user login. - Refactored domain selection logic to streamline user experience. - Added validation for email and password inputs. - Updated configuration handling for self-hosted domains. - Removed unused argon2 parameters and related code.
There was a problem hiding this comment.
Greptile Overview
Summary
This PR adds support for direct user login via command-line flags (--email, --password, --hosting) and corresponding environment variables (INFISICAL_EMAIL, INFISICAL_PASSWORD, INFISICAL_HOSTING), enabling non-interactive authentication flows for CI/CD and automation scenarios.
Key Changes:
- Introduced three new flags and environment variables for direct user authentication
- Added domain configuration support for Infisical Cloud US, EU, and custom self-hosted instances
- Refactored login flow to handle three paths: browser login, interactive CLI login, and direct login
- Extracted validation functions (
validateEmailInput,validatePasswordInput,validateURLInput) for better code reusability - Added
setDirectUserLoginDomain()to handle domain configuration for direct login flows - Removed unused
paramsstruct andgenerateFromPassword()function
Code Quality Improvements:
- Better separation of concerns with extracted helper functions
- Improved error messages with more specific validation feedback
- Added debug logging for environment variable usage
Confidence Score: 3/5
- This PR is generally safe but has a logic issue that could cause confusing user experience
- The implementation is mostly solid with good refactoring and extracted validation functions. However, the
isDirectUserLoginFlagsAndEnvsSet()function uses OR logic that allows partial flag sets (e.g., only --email without --password), which will cause delayed errors whenGetCmdFlagOrEnv()tries to retrieve missing values. This creates a poor UX where users might think they're entering direct login mode but get cryptic errors later. The fix is straightforward - require all three parameters together. - Pay close attention to
packages/cmd/login.go- specifically theisDirectUserLoginFlagsAndEnvsSet()function around line 958
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/cmd/login.go | 4/5 | Adds direct user login via flags/env vars with domain configuration. Refactored code improves readability. Minor logic concern with partial flag/env checking. |
| packages/util/constants.go | 5/5 | Added three new environment variable constants for user authentication - straightforward addition with no issues. |
| packages/util/helper.go | 5/5 | Added debug logging to GetCmdFlagOrEnv - helpful for troubleshooting, no issues identified. |
Sequence Diagram
sequenceDiagram
participant User
participant CLI as Login Command
participant Flags as Flag Parser
participant Domain as Domain Config
participant Auth as Auth Flow
participant API as Infisical API
participant Storage as System Storage
User->>CLI: Execute login command
CLI->>Flags: Check for direct login flags
Flags-->>CLI: Return flag status
alt Domain Selection Required
CLI->>Domain: Configure domain
alt Preset Domain
Domain->>Domain: Apply config
else Custom Domain
Domain->>Domain: Validate URL
Domain->>Domain: Save to config
end
end
alt Browser-based Login
CLI->>Auth: Start browser flow
Auth->>API: Browser authentication
API-->>Auth: Return auth data
else Direct Login
CLI->>Flags: Get user inputs
Flags->>Flags: Validate inputs
Flags-->>CLI: Validated data
CLI->>Auth: Execute CLI login
Auth->>API: Send auth request
alt V3 Success
API-->>Auth: Return token
else SRP Required
API->>Auth: Legacy SRP flow
API-->>Auth: Return auth info
end
end
Auth-->>CLI: Authentication complete
CLI->>Storage: Persist session
CLI->>User: Success message
3 files reviewed, 1 comment
- Added an option to print the JWT token directly in the output for plain output mode. - Enhanced user feedback by displaying the token similarly to other login methods.
- Removed deprecated hosting constants and streamlined the login command logic. - Introduced a new validation function for direct user login flags and environment variables. - Enhanced error messages for missing flags and improved domain configuration handling. - Updated user prompts for clarity during the login process.
- Eliminated a redundant print statement that displayed the preset domain during direct user login. - Improved code clarity by streamlining domain configuration handling.
packages/cmd/login.go
Outdated
| fmt.Println("- Stuck? Join our slack for quick support https://infisical.com/slack") | ||
|
|
||
| // Display JWT token similar to other login methods | ||
| boldPlain := color.New(color.Bold) |
There was a problem hiding this comment.
I'm not sure we actually want to always display this? For user auth I would opt to have this only returned with the --plain tag. I think the idea is that people are able to retrieve the token for things like CI steps, which I think they should be able to achieve by using the --plain tag.
It makes sense to display it for machine identity auth methods because they are expected to always be used as apart of CI steps - user auth is not intended to be used in CI steps usually
There was a problem hiding this comment.
Updated, and the token only shows with the --plain tag
- Eliminated the print statement for the JWT token in the login command to enhance code clarity and streamline user feedback. - This change aligns with recent improvements to the login command's user experience.
Description 📣
PR Description
This PR adds support for non-interactive user authentication via command-line flags and environment variables, enabling automated login workflows for CI/CD pipelines and scripting scenarios.
📋 Changes
New Flags
--email: Email address for user login--password: Password for user loginEnvironment Variables (reuses existing infrastructure)
INFISICAL_EMAIL: Email for authenticationINFISICAL_PASSWORD: Password for authenticationINFISICAL_API_URL: Domain configuration (existing env var)JWT Token Output
--plainflag support: outputs only the JWT token for scriptingLogin Flow (Priority Order)
--emailand--password(or env vars) set → non-interactive--interactiveflag → CLI promptsValidation & Error Handling
Other Improvements
--domainflag orINFISICAL_API_URLenv) for direct loginType ✨
Tests 🛠️
Core Use Cases
./infisical login./infisical login --interactive./infisical login --email "user@example.com" --password "pass" --domain https://app.infisical.com./infisical login --email "user@example.com" --password "pass" --domain https://eu.infisical.com./infisical login --email "user@example.com" --password "pass" --domain https://app.infisical.com --plain./infisical login --email "user@example.com" --password "pass" --domain https://infisical.company.comJWT Token Output
Environment Variables
Error Handling
CI/CD Simulation
Partial Env Var Usage