-
Notifications
You must be signed in to change notification settings - Fork 2
add device auth and token endpoints #2692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 adds support for the OAuth 2.0 Device Authorization Grant flow by exposing two new API endpoints and wiring up a form-encoded HTTP client to back them.
- Introduces
/connect-cloud/device-auth
and/connect-cloud/oauth/token
handlers with request/response models. - Extends the internal HTTP client (
PostForm
) for form-encoded calls and implements aCloudAuthClient
using it. - Updates routing and renames existing
clientFactory
toconnectClientFactory
across service handlers and tests.
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/types/error.go | Added new ErrorDeviceAuth* codes for device flow |
internal/types/api_errors.go | Mapped device-auth error strings to API error codes |
internal/services/api/post_connect_cloud_device_auth.go | Implements device-auth endpoint handler |
internal/services/api/post_connect_cloud_oauth_token.go | Implements token-exchange endpoint handler |
internal/services/api/post_test_credentials.go | Renamed clientFactory to connectClientFactory |
internal/services/api/get_snowflake_connections.go | Swapped clientFactory to connectClientFactory |
internal/services/api/get_deployment_env.go | Swapped clientFactory to connectClientFactory |
internal/services/api/api_service.go | Registered the two new endpoints in the router |
internal/clients/http_client/http_client.go | Added PostForm and doFormEncoded for form data |
internal/clients/cloud_auth/client_cloud_auth.go | Added CreateDeviceAuth /ExchangeToken implementations |
Comments suppressed due to low confidence (1)
internal/clients/http_client/http_client.go:179
- The
doFormEncoded
method referencescontext.Background()
andslog.LevelDebug
but this file doesn’t importcontext
orlog/slog
. Please add the necessary imports or adjust to use the existinglogging.Logger
API.
if log.Enabled(context.Background(), slog.LevelDebug) {
Intent
Resolves #2670.
Resolves #2671.
Adds two endpoints which will be used to authenticate through the OAuth device flow for Connect Cloud. The steps to use these will be as follows:
API requests and responses are as follows:
Type of Change
Approach
The device auth endpoint is a very simple passthrough to our authorization server. It should always succeed at initiating a device auth request.
The token exchange endpoint has specific error handling for certain error codes.
User Impact
No user impact until we start calling this from the extension code.
Automated Tests
Added unit tests for the auth client methods and new endpoints.
Directions for Reviewers
@tyatposit This is WIP - we need to wait for Kyle's auth changes (https://github.com/rstudio/lucid-auth/issues/1320) before we can actually use this.
verificationURIComplete
URL from the response, log in if necessary, and approve the requestChecklist