Skip to content

OIDC token endpoint returns 400 'origin not allowed for client' for CDN-loaded apps #10

Closed

Description

@melvincarvalho

Problem

When Mashlib is loaded from CDN (unpkg.com), the Solid-OIDC login flow fails at the token exchange step with:

400 Bad Request
origin not allowed for client

Root Cause

The oidc-provider library validates CORS requests against the client's registered redirect URIs by default. When a web app like Mashlib is loaded from a CDN domain (unpkg.com) but makes token requests to the Solid server (jss:4000), the origin doesn't match.

Solution

Configure clientBasedCORS in the OIDC provider to allow all origins:

clientBasedCORS: () => true,

This is appropriate for Solid servers because:

  • Solid servers are public and should accept requests from any web app
  • Web apps can be hosted anywhere (CDNs, local development, etc.)
  • The Solid ecosystem relies on apps being able to authenticate against any pod

Affected Files

  • src/idp/provider.js

Testing

  1. Start JSS with --mashlib-cdn --idp flags
  2. Navigate to a protected resource
  3. Click "Sign In" in Mashlib
  4. Complete the login flow
  5. Verify token exchange succeeds

Activity

  1. added a commit that references this issue on Dec 29, 2025
    48614c5
  2. melvincarvalho commented on Dec 29, 2025

    @melvincarvalho
    ContributorAuthor

    Progress Update

    Server-side fixes (PR #11):

    1. ✅ clientBasedCORS: () => true - allows CORS from any origin on token endpoint
    2. ✅ DPoP header added to CORS allowed headers
    3. ✅ Strip iss parameter from authorization redirects (oidc-provider v9+ always includes RFC 9207 iss parameter)

    Current Status

    The OIDC flow completes successfully on the server side:

    • Client registration ✅
    • Authorization request ✅
    • Login/consent ✅
    • Authorization code returned ✅

    However, Mashlib's client-side auth library doesn't make the token exchange request after receiving the code. The error shown is:

    Error: (via loadPrefs) Error: Can't log in: Error: Could not log in
    

    This appears to be a client-side issue in solid-ui/mashlib, not a server issue. The token endpoint is working correctly when tested directly.

    Next Steps

    • Investigate solid-ui's OAuth callback handling
    • Test with a different Solid client (e.g., Penny, or a direct solid-client-authn-browser implementation)
    • Consider opening an issue on the solid-ui or mashlib repository
  3. melvincarvalho commented on Dec 29, 2025

    @melvincarvalho
    ContributorAuthor

    Final Investigation Results

    Server-side OIDC: ✅ Working

    Verified the full OIDC flow works correctly:

    # 1. Client registration works
    curl -X POST http://jss:4000/idp/reg -H "Content-Type: application/json" \
      -d '{"client_name":"Test","redirect_uris":["http://localhost/cb"],...}'
    # → 201 Created
    
    # 2. Token generation works
    curl -X POST http://jss:4000/idp/credentials -H "Content-Type: application/json" \
      -d '{"username":"testoidc","password":"test123"}'
    # → Returns valid access_token with webid claim
    
    # 3. Token works at protected resources
    curl http://jss:4000/testoidc/ -H "Authorization: Bearer <token>"
    # → 200 OK

    Mashlib Client-side: ❌ Not completing token exchange

    Both Mashlib 2.0.0 and 1.11.1 exhibit the same behavior:

    1. Client registration ✅
    2. Authorization request ✅
    3. User login/consent ✅
    4. Authorization code returned ✅
    5. Token exchange NOT attempted ❌

    The browser console shows:

    Error: (via loadPrefs) Error: Can't log in: Error: Could not log in
    

    This error occurs in solid-ui.js before any /idp/token request is made.

    Root Cause

    Mashlib's solid-ui library receives the authorization code but fails to exchange it for tokens. This appears to be a client-side bug in solid-ui's OAuth callback handling, not a server issue.

    Workarounds

    1. Use the /idp/credentials endpoint for programmatic access (works)
    2. Test with a different Solid client (e.g., Penny, solid-client-authn-browser directly)
    3. Open an issue on solid/solid-ui

    PR #11 Status

    The server-side fixes in PR #11 are correct and should be merged:

    • clientBasedCORS: () => true - CORS for token endpoint
    • DPoP header in CORS allowed headers
    • Strip iss parameter from redirects (RFC 9207 compatibility)

    The Mashlib issue is a separate client-side problem.

  4. added a commit that references this issue on Dec 29, 2025
    d4e6cdf
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions