Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds token validation enhancements to prevent silent failures from stale authentication credentials. The changes introduce pre-flight validation checks and a recovery mechanism for MQTT connections.
Key changes:
- Added
has_valid_tokensproperty to validate both JWT and AWS credentials before operations - Enhanced MQTT client initialization to reject creation with expired tokens
- Added
recover_connection()method for explicit token refresh and reconnection flow
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/nwp500/auth.py | Added has_valid_tokens property for combined JWT and AWS credential validation |
| src/nwp500/mqtt_client.py | Enhanced init validation to check token validity and added recover_connection() recovery method |
78025fb to
4145768
Compare
- Add has_valid_tokens property to NavienAuthClient * Checks if tokens exist AND are not expired (JWT + AWS credentials) * Provides pre-flight validation before token-dependent operations * Fails fast instead of silently accepting stale tokens - Enhance NavienMqttClient.__init__ validation * Validates token validity before MQTT client creation * Rejects clients with stale/expired tokens * Clear error message guides users to refresh tokens - Add recover_connection() helper method to NavienMqttClient * Refreshes tokens and attempts reconnection * Useful for recovering from auth-related connection failures * Provides explicit, documented recovery pattern These changes improve error handling and make the library more robust by preventing silent failures due to stale authentication credentials.
4145768 to
edead2a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements three token validation enhancements to improve error handling and prevent silent failures due to stale authentication credentials.
Changes
1. Add
has_valid_tokensProperty (HIGH PRIORITY)src/nwp500/auth.pyImplementation:
2. Enhance
NavienMqttClient.__init__Validation (HIGH PRIORITY)src/nwp500/mqtt_client.pyensure_valid_token()orre_authenticate()New validation:
3. Add
recover_connection()Helper Method (MEDIUM PRIORITY)src/nwp500/mqtt_client.pyExample usage:
Validation
✅ Linting: All checks passed (ruff format + ruff check)
✅ Type checking: No type errors found (mypy)
✅ Tests: 127 tests passed
✅ Custom validation: All three features verified working correctly
Why These Changes Matter
Backward Compatibility
These are additive changes with no breaking changes:
Files Changed
src/nwp500/auth.py: Addedhas_valid_tokenspropertysrc/nwp500/mqtt_client.py: Enhanced init validation + addedrecover_connection()methodRelated Issues
Addresses concerns about token expiration handling and silent MQTT connection failures.