In a Discourse forum discussion titled ‘Using Discourse API to return user data when the “Require authentication to read content on this site, disallow anonymous access.” setting is checked’, users asko and Eric_Hoxworth report that the GET endpoint /users/by-external/{EXTERNAL_ID}.json stops returning user data after enabling the authentication requirement. asko notes they authenticate successfully for POST requests but struggle with GET requests, attempting headers without success. riking advises passing api_key and api_username as URL query parameters, which asko questions for security reasons, citing HTTPS query string risks. riking clarifies that over HTTPS, query parameters are secure since only the server logs them — and suggests using a dedicated admin user for API keys to mitigate exposure. Finally, blake closes the thread, noting that API credentials are now passed via HTTP headers — implying the original issue is resolved in current versions. The discussion highlights a temporary workaround and eventual fix for authenticated API access under restrictive site settings.
I enabled the setting “Require authentication to read content on this site, disallow anonymous access”.
I’m making a GET request to the /users/by-external/{EXTERNAL_ID}.json endpoint, and without the above setting enabled, it returns a user perfectly fine. But when I enable the above setting, the GET request returns nothing.
For reference, I have SSO enabled.
Let me know if there’s a workaround or if I’m thinking about this incorrectly.
Thanks in advance!
Without knowing how Discourse wants to handle this, it seems like an /admin/users/external/{EXTERNAL.ID}/log_out function would be good to have so you could logout a user by their external ID.
(I’m not a ruby expert so I don’t feel comfortable submitting a pull request for this one)
You’ll need to authenticate/log in to make that request. One way to authenticate is to supply a api_key and api_username, which sounds like what you want here. (The other way is to store Cookies.)
Thanks for getting back to me @riking. I’ve been authenticating for the log out call, since it’s a POST request so I can send the api_key and api_username in the request body. Since this call (/users/by-external/{EXTERNAL_ID}.json) is a GET request, it doesn’t make sense to send those in the request body. I tried sending them as a header in the GET request but it wasn’t working. Does this sound like it might be a bug?