Skip to content

feat(scopes): add scopes warning hook - #1842

Merged
Sg312 merged 24 commits into
stagingfrom
improvement/auth-scopes-warning
Nov 8, 2025
Merged

feat(scopes): add scopes warning hook#1842
Sg312 merged 24 commits into
stagingfrom
improvement/auth-scopes-warning

Conversation

@Sg312

@Sg312Sg312 commented Nov 7, 2025

Copy link
Copy Markdown
Collaborator

Summary

Add hook to check if user is missing auth scopes and needs to reauthenticate

Type of Change

  • New feature

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

waleedlatif1and others added 15 commits October 11, 2025 22:23
* improvement(performance): remove unused source/target indices, add index on snapshot id (#1603)
* fix(blog): rename building to blogs with redirect (#1604)
* improvement(privacy-policy): updated privacy policy for google (#1602)
* updated privacy policy for google
* update terms, privacy, and emails to incl address and update verbiage
* feat(guardrails): added guardrails block/tools and docs (#1605)
* Adding guardrails block
* ack PR comments
* cleanup checkbox in dark mode
* cleanup
* fix supabase tools
* fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (#1606)
* fix(inference): fix inference billing when stream is true via API
* add drag-and-drop to deployed chat
* feat(mistal): added mistral as a provider, updated model prices (#1607)
* feat(mistal): added mistral as a provider, updated model prices
* remove the ability for a block to reference its own outluts
* fixed order of responses for guardrails block
* feat(versions): added the ability to rename deployment versions (#1610)
* fix(vulns): fix various vulnerabilities and enhanced code security (#1611)
* fix(vulns): fix SSRF vulnerabilities
* cleanup
* cleanup
* regen docs
* remove unused deps
* fix failing tests
* cleanup
* update deps
* regen bun lock
* fix(debug-mode): remove duplicate debug mode flag (#1714)
* feat(i18n): update translations (#1709)
* improvement(condition): added variable and envvar highlighting for condition input (#1718)
* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data (#1719)
* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data
* apps/sim
* renaming
* remove relative import
* feat(tools): added webflow OAuth + tools (#1720)
* feat(tools): added webflow OAuth + tools
* remove itemId from delete item
* remove siteId
* added webhook triggers + oauth scopes + site/collection selector
* update sample payload for webflow triggers
* cleanup
* fix discord color
* feat(i18n): update translations (#1721)
* improvement(schedule): fix UI bug with schedule modal (#1722)
* fix(already-cancelled-sub): UI should allow restoring subscription
* restore functionality fixed
* fix
@vercel

vercelBot commented Nov 7, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 8, 2025 0:30am

@Sg312Sg312 changed the title Improvement/auth scopes warningfeat(scopes): add scopes warning hookNov 7, 2025

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR implements OAuth scope tracking and validation infrastructure to detect when stored credentials have insufficient or mismatched scopes compared to what the application expects.

Key Changes:

  • Added evaluateScopeCoverage() function to compare granted scopes against canonical scopes defined in provider configuration
  • Extended Connections and Credentials API responses to include scope metadata: canonicalScopes, grantedScopes, missingScopes, extraScopes, and requiresReauthorization
  • Created client-side hooks in use-oauth-scope-status.ts for checking credential authorization status
  • Updated tests to mock new scope evaluation functions

Implementation Details:

  • The scope evaluation logic normalizes and deduplicates scopes, then compares them against canonical scopes from OAUTH_PROVIDERS configuration
  • Both API routes now call evaluateScopeCoverage() for each account and merge scope data into responses
  • The connections route aggregates scope information across multiple accounts for the same provider

Issues Found:

  • The requiresReauthorization flag incorrectly triggers when extra scopes are present (line 696 in oauth.ts) - extra permissions shouldn't require reauth, only missing ones should

Confidence Score: 4/5

  • Safe to merge after fixing the requiresReauthorization logic
  • The implementation is well-structured with proper test coverage and follows the existing patterns in the codebase. The logic issue with extra scopes incorrectly triggering reauthorization needs to be fixed to avoid false warnings to users.
  • apps/sim/lib/oauth/oauth.ts requires attention for the requiresReauthorization logic fix on line 696

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/lib/oauth/oauth.ts4/5Added scope evaluation utilities with one logic issue: requiresReauthorization incorrectly triggers on extra scopes
apps/sim/app/api/auth/oauth/connections/route.ts5/5Integrated scope evaluation into connections API, properly merging scope data across multiple accounts
apps/sim/app/api/auth/oauth/credentials/route.ts4/5Added scope evaluation to credentials API with minor inconsistency in provider parsing approach

Sequence Diagram

sequenceDiagram
participant Client
participant Route as API Route
participant Lib as OAuth Library
participant DB as Database
Client->>Route: Request OAuth connections
Route->>DB: Fetch user accounts
DB-->>Route: Return accounts
loop Process accounts
Route->>Lib: Parse provider ID
Lib-->>Route: Provider details
Route->>Lib: Evaluate scope coverage
Lib->>Lib: Retrieve canonical scopes
Lib->>Lib: Normalize granted scopes
Lib->>Lib: Calculate differences
Lib-->>Route: Scope analysis
Route->>Route: Aggregate data
end
Route-->>Client: Return with scope metadata
Loading

Additional Comments (1)

  1. apps/sim/app/api/auth/oauth/credentials/route.ts, line 121 (link)

    style: use parseProvider utility for consistency instead of manual string splitting

6 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/lib/oauth/oauth.ts Outdated
@Sg312
Sg312force-pushed the improvement/auth-scopes-warning branch from ca57f0c to 3d1846bCompareNovember 8, 2025 00:29
@Sg312
Sg312 merged commit 6cdee53 into stagingNov 8, 2025
3 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/auth-scopes-warning branch November 8, 2025 23:27
waleedlatif1 added a commit that referenced this pull request Nov 9, 2025
* fix(billing): should allow restoring subscription (#1728)
* fix(already-cancelled-sub): UI should allow restoring subscription
* restore functionality fixed
* fix
* Server side logic to check auth scopes
* Fix scopes code
* Remove frontend changes
* Fix tests
* Lint
* Remove log for lint
* Fix scopes check
* Fix conflict
---------
Co-authored-by: Waleed <walif6@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
waleedlatif1 added a commit that referenced this pull request Nov 12, 2025
* fix(billing): should allow restoring subscription (#1728)
* fix(already-cancelled-sub): UI should allow restoring subscription
* restore functionality fixed
* fix
* Server side logic to check auth scopes
* Fix scopes code
* Remove frontend changes
* Fix tests
* Lint
* Remove log for lint
* Fix scopes check
* Fix conflict
---------
Co-authored-by: Waleed <walif6@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto 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

@Sg312@waleedlatif1@icecrasher321