How to get a feed from a password protected Discourse?

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:

「いいね!」 13

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?

「いいね!」 1

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:

「いいね!」 5

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.

「いいね!」 3

API キーは現在、ヘッダーに入れる必要があるのでは、@sam

「いいね!」 4

はい、その通りです!@blake 現在の状況で、個人用 RSS フィードをどのように扱うかについてご意見はありますか?ブラウザや RSS フィードリーダーは、認証用のカスタムヘッダーをサポートしていますか?

これはかなり特殊なユースケースですが、回避策があれば嬉しいですね。

「いいね!」 4

RSS に関連する認証機能は、https://user:password@www.example.com のような URL ベースの基本認証(現在はサポートされていません)や、現在 URL 内で api_key と api_username をサポートしているような仕組みのみです。

URL ベースの認証を完全に廃止できれば理想的でしたが、プライベート RSS のサポートを維持するためには、トピック/カテゴリフィードに対してのみこの種の認証を許可し、将来的には読み取り専用の API キーのサポートも追加する方向が適切だと考えられます。

また、RSS リーダーは通常、フィードを追加するための URL フィールドが 1 つしかないため、仮に RSS がヘッダーのサポートを追加したとしても、ユーザーが認証情報をヘッダーに追加できる場所が提供されていないという問題もあります。

「いいね!」 4

@david さんのスコープ設定に関する作業に関連するアイデアとして、単一の RSS フィードに厳密にスコープされたユーザー API キーを作成する方法があります。これにより攻撃対象領域を最小限に抑えられます。また、そのような超狭いスコープのユーザー API キーの場合は、ヘッダーなしでも認証を許可できます(user_api_key に「このキーは GET による認証に使用可能」というフラグを追加するカラムを設けるなど)。

ここで課題となる点は以下の通りです:

  1. ユーザーがユーザー API キーを生成する仕組みが存在しません。RSS のユースケース向けに何らかの仕組みを構築する必要があり、新しい UX が伴います。どこに追加すべきか(ユーザープロフィールなど)も現時点では不明です。

  2. 特定の RSS フィードにのみスコープを限定する仕組みが存在せず、これを追加する必要があります。

  3. URL の GET パラメータ経由で「許可されたユーザー API キー」を示すフラグが存在せず、これが必要となります。

全体として、これは解決可能な課題だと考えていますが、完璧に動作させるにはおそらく 1〜2 週間程度の作業が必要になるでしょう。

メリットとしては、RSS に関係なく行いたい作業の一部が含まれている点ですが、デメリットとしては、作業の一部が RSS と非常に密結合しており、現在この機能を利用しているユーザーがほとんどいない点です。

優先順位については @codinghorror にお任せします。

「いいね!」 5

私は WordPress と Discourse を連携させており、WordPress 側で SSO を行っています。WordPress の API を使って複数のカテゴリの RSS フィードからサイドバーに最近の投稿を生成しているので、その URL 認証メカニズムを維持できれば嬉しいです。そうしないと、ヘッダー認証オプションを実装するためにカスタムウィジェットを書くという手間に手を染めることになります。つまり、この機能を使っている少数派の一人として、賛成 (+1) です。

「いいね!」 3

これが現在サポートされているかどうか、教えていただけますか?

動作させるのに苦労しています。

API_KEY をクエリ文字列で使おうとすると、以下のエラーが出ます:

要求されたリソースを表示する権限がありません。API ユーザー名またはキーが無効です。

これは少なくともクエリ文字列を読み込もうとしていることを示唆しています。

更新:

まあ、これで何とか動くようになりました。RSS フィードの一部は利用可能ですが、すべてではないようです。API キーの設定を見ると、以下にアクセスできるようです:

読み取り

  • /t/:slug/:topic_id.rss

リストの読み取り

  • /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除外されている のか、ご存知の方はいらっしゃいますか?

「いいね!」 2

API キーを使って RSS を取得するには、正しいデータを取得するために Accept ヘッダーを指定する必要があるようです。

  • Accept ヘッダーを指定せずに RSS を取得すると(例:curl https://bbs.example.com/c/cat.rss?api_key=KEY)、\u003c HTTP/1.1 404 Not Found のページが返される可能性があります。
  • しかし、Accept ヘッダーを指定すれば、RSS の XML を正しく取得できます。例えば:
curl 'https://bbs.example.com/c/cat.rss?api_key=KEY' \
  -H 'application/xhtml+xml' \
「いいね!」 1