Skip to content

Conversation

@akalipetis
Copy link
Member

  1. Use the Legacy CLI for getting a token
  2. If the token is not valid (ie expired), force re-authentication
  3. If the client receives a 401 response, force re-authentication

1. Use the Legacy CLI for getting a token
2. If the token is not valid (ie expired), force re-authentication
3. If the client receives a 401 response, force re-authentication

This comment was marked as outdated.

Copy link

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 introduces authenticated HTTP client functionality for Go using the Legacy CLI to obtain and manage authentication tokens. The implementation includes automatic token refresh and retry mechanisms for handling expired or invalid tokens.

  • Adds OAuth2-based authentication client that integrates with the Legacy CLI for token management
  • Implements automatic retry logic for 401 responses with token refresh
  • Extends configuration schema to support OAuth2 client settings and session management

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/auth/client.go Creates authenticated HTTP client using Legacy CLI token source
internal/auth/legacy.go Implements OAuth2 token source that retrieves tokens from Legacy CLI
internal/auth/transport.go Provides HTTP transport with automatic 401 retry and token refresh
internal/auth/jwt.go Adds JWT parsing utility for extracting token expiry information
internal/auth/transport_test.go Tests the retry mechanism for 401 responses
internal/config/schema.go Extends config schema with OAuth2 and session ID fields
internal/legacy/legacy.go Adds ForceColor option to CLI wrapper
pkg/mockssh/server_test.go Resolves symlinks in temp directory for test stability
internal/config/alt/path_test.go Resolves symlinks in temp directory for test stability
go.mod Updates dependencies including adding golang.org/x/oauth2

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pjcdawkins pjcdawkins force-pushed the feature/authentication branch from 89439ac to 2f203f8 Compare September 3, 2025 15:34
@pjcdawkins
Copy link
Contributor

pjcdawkins commented Sep 3, 2025

Right now this fails the legacy-cli tests

=== RUN   TestApiCurlCommand
    tests.go:69: Running: /home/patrick/Projects/psh/legacy-cli/go-tests/../../cli/dist/platform_linux_amd64_v1/platform api:curl /fake-api-path
Error: Get "http://127.0.0.1/fake-api-path": cannot parse token: jwt: malformed token, expected 3 parts, got 1
    tests.go:71: 
        	Error Trace:	/home/patrick/Projects/psh/legacy-cli/go-tests/tests.go:71
        	            				/home/patrick/Projects/psh/legacy-cli/go-tests/api_curl_test.go:53
        	Error:      	Received unexpected error:
        	            	exit status 1
        	Test:       	TestApiCurlCommand
--- FAIL: TestApiCurlCommand (0.07s)

... but that's just on the test side, we can fix it

@pjcdawkins pjcdawkins merged commit cfda425 into main Sep 4, 2025
1 check passed
@pjcdawkins pjcdawkins deleted the feature/authentication branch September 4, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants