Skip to content

Conversation

@mrubens
Copy link
Collaborator

@mrubens mrubens commented Sep 11, 2025

Important

Adds PKCE-based OAuth integration for Hugging Face, updating UI components, configuration, and localization to support the new authentication flow.

  • Behavior:
    • Adds PKCE-based OAuth flow for Hugging Face in HuggingFace.tsx and WelcomeView.tsx.
    • Updates handleUri.ts to handle Hugging Face OAuth callback.
    • Adds storeHuggingFacePkce message handling in webviewMessageHandler.ts.
  • Configuration:
    • Introduces HUGGING_FACE_OAUTH_CLIENT_ID in oauth-constants.ts.
    • Adds getHuggingFaceAuthUrl() in urls.ts for generating OAuth URLs.
  • UI Components:
    • Updates ApiOptions.tsx and SettingsView.tsx to include Hugging Face settings.
    • Adds Hugging Face provider option in ApiOptions.tsx.
  • Dependencies:
    • Adds pkce-challenge to package.json for PKCE support.
  • Localization:
    • Updates localization files to include Hugging Face descriptions.

This description was created by Ellipsis for 9d94c33. You can customize this summary. It will automatically update as commits are pushed.

@mrubens mrubens requested review from cte and jr as code owners September 11, 2025 03:39
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Sep 11, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the PKCE integration for Hugging Face and found several issues that need attention. The implementation works but has security and code quality concerns that should be addressed.

*/

// Hugging Face OAuth client ID for PKCE flow
export const HUGGING_FACE_OAUTH_CLIENT_ID = "aba045f7-aceb-4e53-9247-5c85d7c2b7cb"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security concern: While OAuth client IDs are public, hardcoding them makes rotation difficult and prevents environment-specific configurations. Consider using environment variables or configuration files to allow overriding for different environments (dev/staging/prod).

headers: { "Content-Type": "application/x-www-form-urlencoded" },
})

const accessToken: string | undefined = response.data?.access_token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation of the access token format. Consider validating the token structure and checking that it's a non-empty string before using it.

}

// Optional state validation (if state was provided in the callback)
if (returnedState && pkceData.state && returnedState !== pkceData.state) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state validation is incomplete. It only checks for mismatch but doesn't verify the state format or prevent replay attacks. Consider adding timestamp validation to ensure the state is fresh (e.g., not older than 10 minutes).

}

await this.upsertProviderProfile(currentApiConfigName, newConfiguration)
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling doesn't clean up stored PKCE data on all error paths. The secrets should be deleted in a finally block to ensure cleanup happens regardless of success or failure.

const state = message.values?.state
if (typeof verifier === "string" && typeof state === "string" && verifier.length > 0 && state.length > 0) {
try {
await provider.context.secrets.store("huggingFacePkce", JSON.stringify({ verifier, state }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using context.secrets for temporary PKCE data isn't ideal as secrets are meant for long-term credentials. Consider using extension global state or in-memory storage for temporary OAuth flow data.

// Open externally via extension
vscode.postMessage({ type: "openExternal", url: authUrl })
} catch (e) {
console.error("Failed to start Hugging Face OAuth:", e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for PKCE challenge generation. The catch block only logs to console but doesn't notify the user. Consider showing a user-friendly error message.

const pkceData = pkceSecret ? JSON.parse(pkceSecret) : undefined

if (!pkceData || !pkceData.verifier || !pkceData.state) {
throw new Error("PKCE verifier or state not found in extension state.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages don't follow the i18n pattern used elsewhere in the codebase. Should use the translation function for consistency.


// HuggingFace

async handleHuggingFaceCallback(code: string, returnedState?: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting common OAuth handling logic. The pattern here is duplicated across Glama, OpenRouter, and Requesty providers. A shared OAuth handler would reduce code duplication and make maintenance easier.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 11, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Sep 11, 2025
@hannesrudolph hannesrudolph added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 11, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Draft / In Progress size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants