Conversation
- Add dedicated refreshToken() method to Api class for standard OAuth2 token refresh - Update refreshTokenIfPossible() to first attempt refresh token flow before fallback - Make TokenResponse.refreshToken optional to handle refresh responses correctly - Update ApiRequest protocol to support authorization header control - Add authorization parameter to all ApiRequest initializers - Fix test implementations to match updated ApiRequest protocol The implementation now follows OAuth2 best practices: 1. First attempts to refresh using the refresh_token grant type 2. Falls back to credential-based login only if refresh fails 3. Properly preserves device ID and stamp during refresh 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements proper OAuth2 refresh token flow for better token management and adds fallback to credential-based login when refresh token fails.
Key changes:
- Added dedicated OAuth2 refresh token flow with fallback to credential-based authentication
- Enhanced ApiRequest protocol to support authorization header control
- Updated TokenResponse model to make refresh token optional for refresh responses
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| KiaMaps/Core/Api/Api.swift | Added new refreshToken() method for OAuth2 refresh token grant type |
| KiaMaps/App/ApiExtensions.swift | Updated token refresh logic to try refresh token first, then fallback to credentials |
| KiaMaps/Core/Api/Models/AuthenticationModels.swift | Made refresh token optional in TokenResponse model |
| KiaMaps/Core/Api/ApiRequest.swift | Enhanced protocol and implementation with authorization parameter |
| KiaTests/AuthenticationTests.swift | Updated mock implementation to match new ApiRequest protocol |
| KiaTests/UIComponentMockDataTests.swift | Fixed parameter name casing in test calls |
Comments suppressed due to low confidence (1)
KiaMaps/Core/Api/Models/AuthenticationModels.swift:1
- Using an empty string as fallback for missing refresh token could cause issues. Consider handling the nil case explicitly or documenting why an empty string is appropriate here.
//
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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
Changes
refreshToken()method in Api class for OAuth2 refresh token grant typerefreshTokenIfPossible()to attempt refresh token flow before credential fallbackImplementation Details
The token refresh now follows OAuth2 best practices with this priority:
Test Plan
🤖 Generated with Claude Code