feat: make username optional for Bearer token authentication#12
Conversation
- Update config validation to require only server and token - Username is now optional; empty username uses Bearer auth - Provided username uses Basic authentication (backward compatible) - Add comprehensive tests for both authentication modes - Update documentation to explain both auth modes Fixes issue where Bearer authentication required unnecessary username parameter.
There was a problem hiding this comment.
Pull request overview
This PR enables Bearer token authentication as a first-class authentication method by making the username parameter optional in the JIRA CLI configuration. The JiraClient already supported both Bearer and Basic authentication modes, but the configuration layer previously required all three parameters (server, username, token). This change aligns the configuration validation with the authentication capabilities, allowing users to configure with just server + token for Bearer auth, while maintaining backward compatibility with username + token for Basic auth.
Key Changes:
- Modified configuration validation to require only server + token (username now optional)
- Updated error messages to explain both authentication modes
- Added comprehensive test coverage for Bearer authentication scenarios
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/config.js | Updated isConfigured() and getRequiredConfig() to support optional username, modified error messages to document both auth modes |
| tests/config.test.js | Added test cases for Bearer authentication mode configuration scenarios |
| tests/jira-client.test.js | Added tests verifying Bearer vs Basic auth mode selection based on username presence |
| tests/commands/config.test.js | Added integration tests for config command with Bearer auth (no username) |
| README.md | Updated documentation to recommend Bearer auth as default with examples for both modes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| out: { | ||
| write: jest.fn() | ||
| }, | ||
| out: jest.fn(), |
There was a problem hiding this comment.
Changed out from an object with a write method to a plain function. This changes the mock interface compared to the previous implementation. Verify that all code calling mockIOStreams.out.write() has been updated to use mockIOStreams.out() instead, or ensure backward compatibility is maintained.
Change '(Bearer auth - not set)' to '(Bearer auth)' to avoid confusion. When username is empty, it means Bearer auth is being used, not that it's 'not set'.
pchuri
left a comment
There was a problem hiding this comment.
Thank you for the review! I've addressed both comments:
Comment 1 - Display message clarity: ✅ Fixed
- Changed from
'(Bearer auth - not set)'to'(Bearer auth)' - You're absolutely right - when username is empty, Bearer auth IS being used, not 'not set'
- Commit: cf4503b
Comment 2 - out interface change: ✅ Verified safe
- Confirmed actual IOStreams implementation (lib/iostreams.js:14-15) has
outas a function withwriteproperty - The config command only uses
io.out(), notio.out.write() - All tests pass (87/87) confirming no backward compatibility issues
- Other tests using
out.write()(in iostreams.test.js) are unaffected as they mock their own IOStreams
The changes are minimal and focused on the config command's needs.
# [2.1.0](v2.0.0...v2.1.0) (2025-12-10) ### Features * make username optional for Bearer token authentication ([#12](#12)) ([d9762ad](d9762ad))
|
🎉 This PR is included in version 2.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
📋 Summary
Make the username parameter optional in jira config command to support Bearer token authentication. The JiraClient already supports both authentication modes (Bearer when username is empty, Basic when username is provided), but the configuration validation layer required username. This change aligns the config layer with the authentication capabilities.
🎯 Type of Change
🔍 Changes Made
lib/config.jsto require only server + token (username optional)isConfigured()to check server + token instead of server + username + tokengetRequiredConfig()to return empty string for missing usernamebin/commands/config.jsto explain both authentication modestests/config.test.jstests/jira-client.test.jstests/commands/config.test.js🧪 Testing
📊 Test Results
🚀 Deployment Notes
📝 Checklist
💬 Additional Notes
Backward Compatibility:
Authentication Modes:
Bearer Token Authentication (Recommended): Server + Token only
Authorization: Bearer <token>headerBasic Authentication (Legacy): Server + Username + Token