שימוש ב-API של node.js (discourse-sdk) כאשר SSO מופעל?

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

ChrisBeach is using the node.js API client (discourse-sdk) to integrate with a Discourse forum configured for SSO (DiscourseConnect). Initially, API requests failed because the client wasn’t authenticated via the SSO provider. After experimenting with including SSO cookies, ChrisBeach received HTML instead of JSON responses. ChrisBeach later realized the issue was not SSO-related but a missing ‘Accept: application/json’ header in the API requests. Adding this header resolved the problem, indicating the SDK may not have been configured correctly for JSON responses from the start.

I’m using the node.js API client (GitHub - 99x/discourse-sdk: Node SDK for discourse forum software · GitHub) for a simple integration with my forum.

I immediately ran into problems as my forum is configured for Discourse SSO (AKA DiscourseConnect). When making API requests I got an error as the API consumer was not “logged in” to my SSO provider website.

As an experiment, I modified the discourse-sdk node.js API client so its requests included the cookies expected by my SSO provider website. This got me a little further.

However, my node.js code gets a payload containing an HTML rendering of the Discourse forum and not the data (in json form) that I expected.

I think I might be taking the wrong approach here. Is there a way for me to bypass Discourse SSO when using the API (i.e. a query string param, a different API endpoint, or a Discourse settings change, perhaps)

I’d appreciate your help.

Thanks

Ah, I think I may have solved my own problem.

I needed to modify the discourse-sdk to include the “Accept” json header in its requests:

request.get({
        url: getUrl,
        headers: {
            'Accept': 'application/json'
        },
    },

Looks like maybe the discourse-sdk didn’t work in the first place, aside from my SSO complications