How to get a feed from a password protected Discourse?

AI-generated summary

The discussion revolves around accessing a password-protected Discourse feed on an external WordPress site using Single Sign-On (SSO). strategeek initially asked for help, and eviltrout suggested generating an API key for a user account and appending it to the URL. However, this approach raises security concerns, as the API key can be used to perform actions as the underlying user account.

eviltrout also warned against generating an “All Users” API key, which could compromise the entire site. dansingerman reported an issue where RSS feeds with read restrictions do not work with API keys, even when the key is valid for the user. This was confirmed to be a bug by eviltrout and later fixed by techAPJ.

However, scombs reported that the fix only resolves the issue for restricted categories, not the “Latest” feed. codinghorror noted that API keys now need to be passed in headers, not URLs. sam and blake discussed the challenges of implementing private RSS feeds with API keys, as most RSS readers do not support custom headers.

sam proposed a solution involving tightly scoped user API keys, but this would require significant development work. xadium expressed interest in maintaining the URL auth mechanism for private RSS feeds, citing a use case where they integrate WordPress and Discourse. Jack_Ukleja reported mixed results when using API keys for private RSS feeds, with some feeds working but others not. sptrf suggested that specifying an accepting header is necessary to fetch the correct RSS data with an API key.

Hello. I need to display password protected Discourse feed on the external site. How to do that?

Other sites suggest using this structure http://[username]:[password]@[domain]/[path]
But for Discourse it doesn’t work.

By the way, the external site that I want to show the feed is a wordpress page. Discourse is linked to this page with SSO.

Any ideas?

I assume you mean RSS feeds.

You can generate an API key for a user account on your site in the admin section. Then you can just append it to any URL like so:

http://meta.discourse.org/latest.rss?api_key=KEYHERE

I should note there are security issues with making that api key visible to users. If someone has it, they can do anything that the underlying user account can do. It would be much better to fetch the RSS server side using the key then only exposing the resulting feed.

Also, be especially careful not to generate an “All Users” key for this. If someone gets that key they can do anything as any user on your site. So just be extra careful :smile:

Great answer, eviltrout. Thank you very much :smile:

We are having the issue that the RSS feeds do not work with an api_key if the categories have read restrictions, even if the api_key is valid for a user that should be able to access the category.

Is this a bug or by design?

That sounds like a bug to me. The API key should function as the user associated with it. Are you passing the correct username through too?

No, I’m not passing a username, as I am using a key associated with a user.

If I try in an unauthenticated session:

http://myserver.example.com/latest.json?api_key=my_api_key

I get the results I expect

If I try

http://myserver.example.com/latest.rss?api_key=my_api_key

I get no results.

So unless RSS has some special case of how to use API keys, I think it may be a bug

This was a bug, now fixed via:

https://github.com/discourse/discourse/commit/f50d4478810a0d5616ba06448dcae51aaeccb192

With the new fix, I am able to view restricted categories in the RSS feed at …

http://myserver.example.com/c/my_category.rss?api_key=my_api_key

but Latest only shows public topics in the RSS feed

http://myserver.example.com/latest.rss?api_key=my_api_key

Is this still unresolved or am I missing something? Thanks.

API 키는 이제 헤더에 포함해야 하지 않나요 @sam?

네, 지원하긴 합니다! @blake 현재 환경에서 사람들이 개인용 RSS 피드를 어떻게 사용할지에 대해 의견이 있으신가요? 브라우저나 RSS 리더가 인증을 위한 커스텀 헤더를 지원하나요?

상당히 드문 사용 사례이지만, 우회 방법이 있으면 좋겠습니다.

RSS와 인증에 관련된 유일한 사항은 https://user:password@www.example.com과 같은 URL 기반의 기본 인증(Basic Auth)에 대한 지원(현재 지원하지 않음)이거나, 현재 URL에서 api_key와 api_username으로 지원하는 것과 유사한 방식입니다.

URL 기반 인증을 완전히 폐기하는 것이 좋았겠지만, 비공개 RSS를 계속 지원하기 위한 앞으로의 방향은 이러한 유형의 인증을 주제/카테고리 피드에만 허용하는 것입니다. 이후에는 읽기 전용 API 키에 대한 지원도 추가할 수 있습니다.

문제는 RSS 리더가 피드를 추가할 때 URL 입력란 하나만 제공한다는 점입니다. 따라서 RSS가 헤더를 지원하더라도, 리더에 헤더에 자격 증명을 추가할 곳이 없습니다.

@david의 스코핑 작업과 관련되어 여기에서 떠오르는 아이디어 중 하나는, 단일 RSS 피드에 엄격하게 스코프가 지정된 사용자 API 키를 만들 수 있다는 것입니다. 이렇게 하면 공격 표면이 작아지고, 이러한 경우처럼 초소형 스코프의 사용자 API 키를 사용하는 경우에는 헤더 없이도 허용할 수 있습니다(사용자 API 키에 해당 키가 GET 인증에 사용될 수 있음을 나타내는 컬럼을 추가하는 방식).

여기서 도전 과제는 다음과 같습니다:

  1. 사용자가 사용자 API 키를 생성할 수 있는 메커니즘이 없습니다. RSS 사용 사례를 위해 무언가를 구축해야 하며, 이는 새로운 UX를 포함하게 됩니다. 어디에 추가해야 할지 확실하지 않습니다. 아마도 사용자 프로필에 추가할 수 있겠지만, 모르겠습니다.

  2. 특정 RSS 피드 하나에만 스코프를 좁힐 수 있는 메커니즘이 없으며, 이를 추가해야 합니다.

  3. URL GET 매개변수를 통해 "허용된 사용자 API 키"를 식별할 수 있는 플래그가 없으며, 이를 위해 필요합니다.

전체적으로 이 문제는 해결할 수 있다고 보지만, 정확히 작동하도록 만드는 데는 아마도 1~2주 정도의 작업량이 필요할 것입니다.

장점은 이 작업 중 일부는 RSS와 무관하게 우리가 하고 싶은 작업이라는 점이지만, 단점은 일부 작업이 RSS와 매우 강하게 결합되어 있고, 요즘 이 기능을 사용하는 사람이 매우 적다는 점입니다.

어떻게 우선순위를 정할지는 @codinghorror의 판단에 맡기는 것 같습니다.

저는 WordPress와 Discourse를 SSO를 통해 연동하고 있습니다. API를 사용해 여러 카테고리의 RSS 피드를 활용하여 WordPress에서 최근 게시물 사이드바를 생성하고 있기에, 이를 위해 URL 인증 메커니즘을 유지하고 싶습니다. 그렇지 않으면 헤더 인증 옵션을 구현하기 위해 커스텀 위젯을 직접 작성해야 하는 번거로움을 감수해야 합니다. 따라서 이 기능을 사용하는 소수의 사용자 중 한 명으로서 +1을 표합니다.

현재 이것이 지원되는지 아닌지 알려줄 수 있는 사람이 있을까요?

동작하도록 만드는 데 어려움을 겪고 있습니다.

쿼리 문자열에 API_KEY를 사용하려고 하면 다음과 같은 오류가 발생합니다:

요청한 리소스를 볼 권한이 없습니다. API 사용자 이름 또는 키가 유효하지 않습니다.

이는 적어도 쿼리 문자열을 읽으려고 시도하고 있음을 시사합니다.

업데이트:

이제 어찌어찌 작동하는 것 같습니다. RSS 피드의 일부만 사용 가능한 것 같고, 모두는 아닌 것 같습니다. API 키 설정을 살펴보면 다음을 액세스할 수 있는 것 같습니다:

읽기(read)

  • /t/:slug/:topic_id.rss

목록 읽기(read lists)

  • /c/*category_slug_path_with_id.rss
  • /top/all.rss
  • /top/yearly.rss
  • /top/quarterly.rss
  • /top/monthly.rss
  • /top/weekly.rss
  • /top/daily.rss

이것이 기본적인 /latest.rss와 /top.rss를 제외하는 이유가 무엇인지 아는 사람이 있을까요?

API 키를 사용하여 RSS를 가져올 때, 올바른 데이터를 가져오려면 accept 헤더를 지정해야 하는 것 같습니다.

  • curl https://bbs.example.com/c/cat.rss?api_key=KEY처럼 accept 헤더를 지정하지 않고 RSS를 가져오면 < HTTP/1.1 404 Not Found 페이지가 반환될 수 있습니다.
  • 그러나 accept 헤더를 지정하면 RSS XML을 올바르게 가져올 수 있습니다. 예를 들어:
curl 'https://bbs.example.com/c/cat.rss?api_key=KEY' \
  -H 'application/xhtml+xml' \