Skip to content

Add first-party OAuth start URLs for provider authorization #782

Open

Description

@dcramer

Problem

Junior currently sends users directly to provider OAuth authorization URLs when a provider requires authorization. This works for normal cases, but it leaves two reliability problems:

  • For generic plugin OAuth, the provider authorization URL and Junior oauth-state:* record are created when the agent pauses. The callback state is valid for only 10 minutes.
  • For MCP OAuth, the MCP SDK creates the upstream authorization URL during the auth challenge. Junior can store its local MCP auth session longer, but the provider authorization URL has already been minted and may expire or become invalid before the user clicks it.

Recent MCP auth debugging also showed that provider-side redirect URI validation can fail when dynamic OAuth client information is stale or was registered for a different Junior callback URL. That specific stale-client bug should be fixed separately, but a first-party start URL would make the OAuth initiation boundary clearer and more controllable.

Proposal

Send a Junior-owned authorization start URL in Slack instead of sending provider authorization URLs directly.

Suggested routes:

  • GET /api/oauth/start/:provider for generic plugin OAuth
  • GET /api/oauth/start/mcp/:provider for MCP OAuth

The Slack message would contain only the Junior URL. When the user clicks it, Junior should:

  1. Validate a signed or server-stored auth intent with a longer TTL than provider callback state.
  2. Verify the intent still belongs to the requesting user/provider/session.
  3. Create the short-lived provider OAuth state at click time.
  4. For MCP, initiate the MCP SDK authorization flow at click time so PKCE, state, client registration, and provider authorize URL are fresh.
  5. Redirect the browser to the upstream provider authorization endpoint.

The callback routes can stay largely the same: provider redirects still land on the existing Junior callback paths after the user approves.

Rationale

This avoids minting provider authorization URLs before the user is ready to use them. It gives Junior control over auth-link lifetime and error pages, reduces Slack-visible provider URL exposure, and creates a single place to handle stale intents, superseded requests, and provider-specific retry messaging.

This should apply to both MCP and non-MCP OAuth. A simple redirect proxy to the already-stored provider URL is not enough for MCP, because it would not refresh provider-side state or PKCE; the upstream OAuth authorization flow needs to start when the user opens Junior's link.

Acceptance Criteria

  • Slack auth messages for both plugin OAuth and MCP OAuth contain Junior-owned start URLs, not provider authorize URLs.
  • Generic plugin OAuth creates oauth-state:* only when the start URL is opened.
  • MCP OAuth creates or refreshes the upstream provider authorize URL only when the start URL is opened.
  • Existing callback resume behavior remains unchanged for successful authorization.
  • Expired or stale Junior start links render a safe, actionable HTML response and do not resume superseded Slack work.

Activity

  1. added
    enhancement
    on Jul 7, 2026
  2. dcramer commented on Jul 10, 2026

    @dcramer
    MemberAuthor

    Investigation notes

    The desired click-time OAuth behavior requires more than routing by provider name.

    Junior’s browser request is not authenticated as the Slack user, so a URL such as /api/oauth/start/github cannot safely determine:

    • which actor should own the resulting credentials;
    • which blocked conversation/session should resume;
    • which requested scope applies; or
    • which of several concurrent authorization requests initiated the flow.

    The start link therefore needs an opaque, high-entropy authorization-intent identifier backed by server-side state.

    Separate intent from attempt

    There should be two lifecycles:

    1. Authorization intent

      • Created when the agent encounters missing authorization.
      • Identifies actor, provider, scope, and resume context.
      • Produces a stable, privately delivered Junior URL.
      • Can have a relatively long TTL, such as 24 hours.
    2. Provider OAuth attempt

      • Created only after explicit browser confirmation.
      • Generates provider state, PKCE, dynamic registration, and the upstream authorization URL.
      • Keeps the current short TTL.
      • May be recreated if the provider attempt fails or is declined.

    Browser prefetching

    The start route should not initiate OAuth on GET. Slack unfurling, security scanners, and browser prefetching may visit links automatically.

    Recommended flow:

    GET /api/oauth/start/<intent>
      → render confirmation page
    
    POST /api/oauth/start/<intent>
      → create fresh OAuth attempt
      → redirect to provider
    

    The intent must not be consumed by the initial GET.

    MCP-specific constraint

    MCP OAuth currently performs discovery, dynamic client registration, PKCE generation, and authorization URL creation while handling the agent’s 401 challenge.

    Moving this to click time must preserve silent use and refresh of credentials for already-connected users. The runtime needs to distinguish:

    • existing credentials that can be used or refreshed without interaction;
    • an interactive authorization requirement that should park the run and create only an intent; and
    • click-time SDK authorization that performs discovery/registration and generates the provider redirect.

    #783 fixes stale cached MCP client registrations, but it is a mitigation rather than the click-time lifecycle change.

    Proposed acceptance criteria

    • Slack receives a private Junior-owned URL rather than a provider authorization URL.
    • The URL contains an opaque random intent identifier, not actor or resume data.
    • A GET performs no upstream OAuth requests and creates no OAuth state.
    • Explicit confirmation creates fresh provider state and redirects upstream.
    • Generic OAuth and MCP use the same intent boundary.
    • MCP discovery, dynamic registration, and PKCE happen at click time.
    • Existing MCP credentials continue to work and refresh silently.
    • Failed or declined attempts can be retried from the same unexpired intent.
    • Concurrent confirmation requests cannot create conflicting attempts.
    • Existing callback freshness rules continue to prevent stale thread resumption.
    • Authorization links remain private and never enter model context.

    Suggested delivery

    1. Introduce authorization intents and migrate generic/plugin OAuth, including slash-command linking.
    2. Move MCP interactive authorization behind the same start boundary while preserving non-interactive credential refresh.

    A more precise summary for the future implementation is: defer interactive OAuth attempt creation until explicit user confirmation. This captures the identity-binding, prefetch, PKCE, and MCP-refresh requirements.

  3. dcramer commented on Jul 11, 2026

    @dcramer
    MemberAuthor

    RCA linkage: click-time authorization intents are the correct long-term interaction boundary, but the current attempt state also needs independent lifecycle repair.

    #833 tracks lazy/atomic MCP attempts, orphan-session cleanup, reused-link viability, and idempotent callback claim. #840 tracks terminal denial/failure outcomes and durable continuation scheduling. #836 tracks DCR/refresh concurrency.

    These should establish the attempt state machine that this issue's click-time intent layer can create safely.

    Umbrella: #843.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions