לא ניתן לבדוק את Discourse Connect ב-localhost

סיכום מבוסס בינה מלאכותית

Sky020 is attempting to integrate Discourse badges with their platform using Discourse Connect, not for login purposes, but to link user accounts. They’re encountering CORS errors during redirection from localhost:3000/discourse/connect to https://forum.freecodecamp.org/session/sso_provider, despite configuring Discourse Connect provider secrets. The error indicates missing Access-Control-Allow-Origin headers. blattersturm suggests the redirection flow is intended for content frames (e.g., login pages in iframes), not fetch calls, and recommends using a popup window instead to avoid CORS and cross-origin cookie issues. The setup involves freecodecamp.org (platform), forum.freecodecamp.org (Discourse), and local dev servers at localhost:3000 (server) and localhost:8000 (client). Relevant code is in a GitHub PR that constructs the SSO redirect URL with payload and signature. The team seeks guidance to resolve the CORS block while maintaining their non-login use case.

Hello all,

We are wanting to integrate Discourse badges with our platform. That is, allow a user to connect their Discourse account to their account on our platform.

To link the accounts, we thought Discourse Connect would be the way to go. However, we have come into CORS errors with the redirection:

Access to fetch at 'https://forum.freecodecamp.org/session/sso_provider?sso=<hash>'
(redirected from 'http://localhost:3000/discourse/connect') from origin
'http://localhost:8000' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.

I have tried a whole bunch of settings for Discourse Connect, including adding server, client, and Discourse addresses to discourse connect provider secrets, but to no avail.

To clarify: We do not want to use Discourse Connect to log in to anything.

Locations

  • freecodecamp.org - platform domain
  • forum.freecodecamp.org - Discourse instance subdomain
  • localhost:3000 and localhost:8000 - server and client of freecodecamp.org development environment

Relevant code:
https://github.com/freeCodeCamp/freeCodeCamp/pull/43168/files#diff-c99b1f4c50468e6835c7456cff5841cdd1cbe76ca7a2ac1d15893f839ff37799R278

return res.redirect(
    `${FORUM_LOCATION}/session/sso_provider?sso=${URL_ENCODED_PAYLOAD}&sig=${HEX_SIGNATURE}`
  );

Any assistance would be much appreciated.

I believe this redirection flow is meant for a content frame, not a fetch call. For example, any case where you’d have to redirect to the login page and not be redirected back would not work, and cross-origin cookies would be problematic like this as well.

Try an old-fashioned popup window? :stuck_out_tongue: