Using node.js (discourse-sdk) API when SSO is enabled?

I’m using the node.js API client (GitHub - 99x/discourse-sdk: Node SDK for discourse forum software) 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

1 Like