You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds support for expiring oauth tokens. Using expiring tokens ensures that should a token ever leak, the exposure is limited by the lifetime of the oauth token. There is an influx in security incidents going on around the world because threat actors are finding oauth tokens and weaponizing them.
Type of change
Dependency upgrade
Bugfix (non-breaking change which fixes an issue)
New feature (which adds functionality)
Breaking change (fix/feature causing existing functionality to break)
This PR adds support for expiring OAuth credentials to the device authentication flow, allowing callers to refresh tokens and update existing API clients.
Changes:
Add refresh-token handling, expiration timestamps, and credential validation.
Allow access-token replacement without recreating API namespaces.
Add tests for refresh responses, error handling, cancellation, and header preservation.
File
Description
tests/device/test_refresh.py
Tests token refresh, expiration, failures, and token replacement.
tests/common.py
Adds async context-manager support to mock responses.
aiogithubapi/models/login_oauth.py
Validates credentials and calculates expiration timestamps.
aiogithubapi/github.py
Exposes token replacement on the public API client.
aiogithubapi/device.py
Adds token refresh and captures activation request timing.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Token changes can leave an old Authorization credential active, and refresh requests with automatic HTTP-error raising can misclassify authentication and rate-limit failures as connection errors.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Token updates leave the configured Authorization header in effect
aiogithubapi/client.py:87
If the client was constructed with headers={'Authorization': 'token old'}, both set_token('new') and set_token(None) leave that credential active. GitHubBaseRequestDataModel.headers applies the configured headers after the token-derived header, so subsequent requests still authenticate with the old token. Remove or update the base Authorization override here while preserving the other configured headers.
Disable automatic status raising to classify refresh responses
aiogithubapi/device.py:241
With an injected aiohttp.ClientSession(raise_for_status=True), this request inherits automatic HTTP-error raising. A 400/401 rejected refresh token or a 429 response then raises ClientResponseError before this block is entered and is caught as GitHubConnectionException, bypassing the authentication and rate-limit classification below. Explicitly pass raise_for_status=False so this method can inspect and classify those responses.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A successful response with an explicitly null refresh token is accepted, risking loss of the stored refresh token and preventing future access-token renewal.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Reject null refresh tokens in successful OAuth responses
aiogithubapi/device.py:261
A successful response containing "refresh_token": null bypasses this fallback and is accepted by GitHubLoginOauthModel. A caller persisting the returned credentials would overwrite its refresh token with None and lose the ability to renew the access token. Reject an explicitly null refresh token as a malformed response before constructing the model.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues were identified for the OAuth credential refresh and token-replacement changes.
No open issues 🎉
Review effort: Balanced
This branch has not been deployed
No deployments
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
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.
Description
This PR adds support for expiring oauth tokens. Using expiring tokens ensures that should a token ever leak, the exposure is limited by the lifetime of the oauth token. There is an influx in security incidents going on around the world because threat actors are finding oauth tokens and weaponizing them.
Type of change
Checklist
scripts/test)scripts/lint)