# 未ログインユーザーが非公開ページをリクエストした際の自動ログイン設定

**URL:** <https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142>\
**Category:** Feature\
**Created:** [2019 年 10 月 16 日午前 8:40 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142 "2019-10-16T08:40:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trobiyo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trobiyo/32/311872_2.png) [@trobiyo](https://meta.discourse.org/u/trobiyo)\
**Post date:** [2019 年 10 月 16 日午前 8:40 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142/1 "2019-10-16T08:40:28Z")

</div>

みなさん、こんにちは。

Discourse フォーラムへのログインに関する改善案を提案させていただきます。以前からリクエストがあったか、または実装済みの機能かどうかはわかりませんが、関連するトピックは見つかりませんでした。

別の URL からアクセスしてきた場合に、フォーラムへの自動ログイン機能（またはそれに準ずる機能）が利用できればよいのですが。具体的には、以下のようなシナリオを想定しています。

TL0（レベル 0）のユーザーにのみ許可されているカテゴリ（つまり、ログインしたユーザーのみが閲覧できるカテゴリ）があるとします。このカテゴリへのリンクを誰かに送信すると、以下のメッセージが表示されます。

![image](https://global.discourse-cdn.com/meta/original/3X/3/1/313048c77c57ec1f321aee511dcf87219bdd0ae6.png)

ここでユーザーがログインすると、カテゴリページではなくメインページにリダイレクトされてしまい、本来のターゲット URL が失われてしまいます。

認証方法が 1 つだけ（例：OAuth2）の場合、このメッセージを表示する代わりにユーザーを自動的にログインさせることは可能でしょうか。そうすれば、ユーザーは期待していたターゲット URL を失うことなく、直接「非公開」側のページへアクセスできるようになります。

これは `/wizard` のようなページにも当てはまります。ログインしていない人にこのリンクを送ると、ログイン後にメインページに飛ばされ、その後ユーザーが手動で `/wizard` パスへ再度移動しなければならなくなります。

ご意見をお聞かせください。これに類似した解決策はありますか？

よろしくお願いいたします。  
イスマエル

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019 年 10 月 16 日午前 9:00 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142/2 "2019-10-16T09:00:13Z")

</div>

はい、これに関する既存のトピックは他にもあります。一般的な問題としては、この動作によってプライベートなコンテンツの存在が露見してしまう点です。

---

<div class="post-metadata">

**Author:** ![trobiyo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trobiyo/32/311872_2.png) [@trobiyo](https://meta.discourse.org/u/trobiyo)\
**Post date:** [2019 年 10 月 16 日午前 10:05 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142/3 "2019-10-16T10:05:04Z")

</div>

ええ、その意味では、適切なバランスはセキュリティに最適化されていると推測します。少なくとも考慮してくださったのは光栄です。

ありがとうございます！

では、  
イスマエル

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019 年 10 月 16 日午後 6:11 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142/4 "2019-10-16T18:11:50Z")

</div>

これをデフォルトでオフのオプション設定として追加する可能性もありますし、その案には賛成です。これに関する他のトピックでは、賛成・反対の議論がより詳しく行われています。

また、関連するサイト設定についても、@danj によって同様の方針でコミットされました。

> <https://github.com/discourse/discourse/pull/8014>
>
> If the setting is turned on, then the user will receive information
> about the s…ubject: if it was deleted or requieres some special access to
> a group (only if the group is public). Otherwise, the user will receive
> a generic #404 error message. For now, this change affects only the
> topics and categories controller.
> 
> This commit also tries to refactor some of the code related to error
> handling. To make error pages more consistent (design-wise), the actual
> error page will be rendered server-side.
> 
> \---
> 
> \### Preview
> 
> \* Topic in a secret category (with public group)
> 
> \<img width="1135" alt="topic in secret category" src="https://user-images.githubusercontent.com/4147664/63161475-d9fd6d00-c028-11e9-8e0a-6c8595d73c32.png"\>
> 
> \* Deleted topic in a public category (with public group)
> 
> \<img width="1135" alt="a deleted topic" src="https://user-images.githubusercontent.com/4147664/63161465-d538b900-c028-11e9-88b9-0587fc763645.png"\>
> 
> \* Deleted topic in a secret category
> 
> \<img width="1135" alt="deleted topic in secret category" src="https://user-images.githubusercontent.com/4147664/63161491-e2ee3e80-c028-11e9-83a8-39bb46494069.png"\>
> 
> \* Topic in a secret category (with private group)
> 
> \<img width="1135" alt="topic in super secret category" src="https://user-images.githubusercontent.com/4147664/63161500-e8e41f80-c028-11e9-8a98-ca3534288849.png"\>
> 
> \* Secret category (with a public group)
> 
> \<img width="1135" alt="category page" src="https://user-images.githubusercontent.com/4147664/63161513-ee416a00-c028-11e9-87ef-45943576dbaa.png"\>

---

<div class="post-metadata">

**Author:** ![trobiyo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trobiyo/32/311872_2.png) [@trobiyo](https://meta.discourse.org/u/trobiyo)\
**Post date:** [2019 年 10 月 17 日午前 8:54 UTC](https://meta.discourse.org/t/auto-login-setting-when-private-pages-are-requested-by-unlogged-users/131142/5 "2019-10-17T08:54:04Z")

</div>

素晴らしいアイデアですね。この新しく生成されたページからログインできるのであれば、ユーザーは最終的に目的の URL に到達し、経路を失うことなく移動できるようになるはずです（例えば、`/wizard` にアクセスすると詳細な 404 ページが表示され、ログイン後に `/wizard` のパスにリダイレクトされるような仕組みです）。

よろしくお願いいたします、  
イスマエル
