Skip to content

feat: make username optional for Bearer token authentication#12

Merged
pchuri merged 2 commits intomainfrom
feat/optional-username-bearer-auth
Dec 10, 2025
Merged

feat: make username optional for Bearer token authentication#12
pchuri merged 2 commits intomainfrom
feat/optional-username-bearer-auth

Conversation

@pchuri
Copy link
Copy Markdown
Owner

@pchuri pchuri commented Dec 10, 2025

📋 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧪 Test improvements
  • 🔧 Code refactoring
  • ⚡ Performance improvements

🔍 Changes Made

  • Updated lib/config.js to require only server + token (username optional)
  • Modified isConfigured() to check server + token instead of server + username + token
  • Updated getRequiredConfig() to return empty string for missing username
  • Updated error messages in bin/commands/config.js to explain both authentication modes
  • Added comprehensive tests for Bearer authentication mode in tests/config.test.js
  • Added tests for Bearer vs Basic auth mode selection in tests/jira-client.test.js
  • Added integration tests for config command without username in tests/commands/config.test.js
  • Updated README.md to document both authentication modes with examples
  • Updated configuration documentation to recommend Bearer auth as default

🧪 Testing

  • All existing tests pass
  • New tests added for new functionality
  • Manual testing completed
  • Code coverage maintained/improved

📊 Test Results

Test Suites: 7 passed, 7 total
Tests:       87 passed, 87 total
Snapshots:   0 total
Time:        0.328 s

🚀 Deployment Notes

  • No special deployment steps required
  • Requires environment variable changes
  • Requires dependency updates
  • Other:

📝 Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

💬 Additional Notes

Backward Compatibility:

  • ✅ Existing configs with username continue to work (Basic auth)
  • ✅ Environment variables unchanged (JIRA_HOST already supports optional username)
  • ✅ No breaking changes to CLI flags or behavior
  • ✅ Only making username optional, not removing it

Authentication Modes:

  1. Bearer Token Authentication (Recommended): Server + Token only

    • Uses Authorization: Bearer <token> header
    • Simpler configuration
  2. Basic Authentication (Legacy): Server + Username + Token

    • Uses HTTP Basic Auth with username and token
    • Backward compatible with existing configurations

- 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.
@pchuri pchuri requested a review from Copilot December 10, 2025 03:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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'.
Copy link
Copy Markdown
Owner Author

@pchuri pchuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 out as a function with write property
  • The config command only uses io.out(), not io.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.

@pchuri pchuri merged commit d9762ad into main Dec 10, 2025
5 checks passed
@pchuri pchuri deleted the feat/optional-username-bearer-auth branch December 10, 2025 03:20
github-actions bot pushed a commit that referenced this pull request Dec 10, 2025
# [2.1.0](v2.0.0...v2.1.0) (2025-12-10)

### Features

* make username optional for Bearer token authentication ([#12](#12)) ([d9762ad](d9762ad))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants