# Discourse OAuth2 基础

**URL:** https://meta.discourse.org/t/discourse-oauth2-basic/33879
**Category:** Plugin
**Tags:** official, oauth2, auth-plugins, included-in-core
**Created:** [2015年九月29日 16:27 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879 "2015-09-29T16:27:19Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![jmlord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmlord/32/354569_2.png) [@jmlord](https://meta.discourse.org/u/jmlord)
#### Post date: [2023年十二月8日 16:15 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/315 "2023-12-08T16:15:16Z")

</div>

我找到了问题：Header 没有设置为“Content-Type: application/json”。我看到 @qlands 上面的问题也是一样的。

---

<div class="post-metadata">

### Author: ![jmlord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmlord/32/354569_2.png) [@jmlord](https://meta.discourse.org/u/jmlord)
#### Post date: [2023年十二月8日 16:15 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/316 "2023-12-08T16:15:50Z")

</div>

对我来说，唯一剩下的问题和 @nodomain 的一样：账户创建成功了，但头像没有包含在内。示例响应：

```plaintext
Body: {
  "access_token":"...",
  "token_type":"bearer",
  "expires_in":"3600",
  "scope":"profile",
  "profile" : {
    "id":1234,
    "email": "...",
    "name": "...",
    "picture": "https://somedomain.com/somevalidpicture.jpg"
  }
}

```

并且它被正确解析了，因为它出现在以下日志中：

```plaintext
OAuth2 Debugging: after_authenticate response:

creds: {"token"=>"...", "expires_at"=>1702053692, "expires"=>true}
uid: 1234
info: {"email"=>"...", "name"=>"...", "avatar"=>"https://somedomain.com/somevalidpicture.jpg"}
extra: {}

```

我检查了图片地址是正确的，并且尺寸是 300x300。

关于这个问题有什么想法吗？

编辑：有人刚创建了一个账户，它从 Gravatar 获取了图片。也许 JSON 中的有效图片被 Gravatar 返回的空白结果覆盖了？

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [2024年四月3日 19:14 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/317 "2024-04-03T19:14:17Z")

</div>

# Authentik 作为 OAuth 提供商

**我目前正在尝试使用 Authentik，想问问是否有人在 Discourse 中使用过它？**

> **[Welcome | authentik](https://goauthentik.io)**
>
> Bring all of your authentication into a unified platform.

不幸的是，我还没有找到关于 Discourse 的官方支持文档。

> **[Integrations overview | authentik](https://integrations.goauthentik.io/)**
>
> What is an integration?

有很多设置需要调整 😃

Portainer 的 OAuth 实现要简单得多。

 ![Bildschirmfoto 2024-04-03 an 21.08.58](https://global.discourse-cdn.com/meta/original/4X/7/d/e/7deb5af88706912a37c96e2df922e33087773b2d.jpeg)

Portainer，仅供参考：

 ![Bildschirmfoto 2024-04-03 an 21.11.59](https://global.discourse-cdn.com/meta/original/4X/a/a/5/aa5b33adba0df3920a9a3fdb96635fa8352c6d34.png)

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [2024年五月20日 22:59 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/318 "2024-05-20T22:59:13Z")

</div>

你好吗？我想在 Discourse 和 Ghost 中实现 SSO w/Authentik，但我的项目目前处于待定状态。

任何建议都将不胜感激 🙂

---

<div class="post-metadata">

### Author: ![yyue](https://avatars.discourse-cdn.com/v4/letter/y/ed655f/32.png) [@yyue](https://meta.discourse.org/u/yyue)
#### Post date: [2024年六月15日 19:00 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/319 "2024-06-15T19:00:59Z")

</div>

有人遇到过 SSO 位于内部网络，而 Discourse 尝试使用内部 IP 地址访问 SSO 站点时变得无法访问的问题吗？

```plaintext
tail -f production.log

(oauth2_basic) Setup endpoint detected, running now.
(oauth2_basic) Request phase initiated.
Started POST "/presence/update" for 10.10.10.10 at 2024-06-15 18:19:44 +0000
Processing by PresenceController#update as */*
  Parameters: {"client_id"=>"xxx", "present_channels"=>["/chat-user/core/1"]}
Completed 200 OK in 26ms (Views: 0.2ms | ActiveRecord: 0.0ms | Allocations: 1895)
Started GET "/auth/oauth2_basic/callback?code=xxxx&state=xxxx" for 10.10.10.10 at 2024-06-15 18:19:49 +0000
(oauth2_basic) Setup endpoint detected, running now.
(oauth2_basic) Callback phase initiated.
OAuth2::ConnectionError (FinalDestination: all resolved IPs were disallowed)
lib/final_destination/ssrf_detector.rb:105:in `lookup_and_filter_ips'
lib/final_destination/http.rb:15:in `connect'
lib/middleware/omniauth_bypass_middleware.rb:43:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
lib/middleware/anonymous_cache.rb:391:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:14:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:289:in `call'

```

网页错误

```plaintext
糟糕
运行此讨论论坛的软件遇到了意外问题。很抱歉给您带来不便。

错误详情已记录，并已生成自动通知。我们会进行查看。

无需进一步操作。但是，如果错误状况持续存在，您可以通过在站点的反馈类别中发布讨论主题来提供更多详细信息，包括重现错误的步骤。

```

我检查了防火墙日志，但没有发现任何阻止记录！此外，Discourse 和 SSO 都位于内部网络，因此不应该有任何防火墙阻止或请求拦截问题！

但是，当我将 SSO 站点的 IP 地址指向外部公共网络时，它又恢复正常了！

这是插件中的错误还是我这边的配置问题？

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2024年七月1日 14:17 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/320 "2024-07-01T14:17:44Z")

</div>

您可以将内部 SSO 站点的 वापरा名添加到“allowed\_internal\_hosts”站点设置中。然后 Discourse 将能够连接到它。

---

<div class="post-metadata">

### Author: ![Coding\_Shark](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/coding_shark/32/441510_2.png) [@Coding\_Shark](https://meta.discourse.org/u/Coding_Shark)
#### Post date: [2024年八月21日 03:59 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/321 "2024-08-21T03:59:05Z")

</div>

如何将 URL 中的 _client\_id_ 更改为 _appid_？  
我的服务器不支持 URL 中的 client\_id，只支持 appid。  
我必须修改插件。  
请帮帮我。

---

<div class="post-metadata">

### Author: ![nosguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nosguy/32/463164_2.png) [@nosguy](https://meta.discourse.org/u/nosguy)
#### Post date: [2024年十一月9日 19:54 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/322 "2024-11-09T19:54:04Z")

</div>

一年后，您仍在帮助处理此帖子！谢谢！！Authentik 现在对我来说很好用。

---

<div class="post-metadata">

### Author: ![Loc\_Nguyen\_Vinh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/loc_nguyen_vinh/32/488342_2.png) [@Loc\_Nguyen\_Vinh](https://meta.discourse.org/u/Loc_Nguyen_Vinh)
#### Post date: [2025年二月13日 10:54 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/323 "2025-02-13T10:54:16Z")

</div>

您好，我正在使用 Zalo 的 Oauth2，但遇到了附件中的问题。有人知道原因吗？

我配置的回调 URL 是：[https://sphere.daviteq.com/auth/basic\_oauth2/callback](https://sphere.daviteq.com/auth/basic_oauth2/callback)

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/d/b/9dbefbf894616e69b1ec0fa5005fffdf868d1e05.png)

---

<div class="post-metadata">

### Author: ![marlowleon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marlowleon/32/508384_2.png) [@marlowleon](https://meta.discourse.org/u/marlowleon)
#### Post date: [2025年六月18日 22:21 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/325 "2025-06-18T22:21:15Z")

</div>

有人能分享一个 authentik 配置吗？我相当确定我已经正确设置了一切，但仍然收到 (oauth2\_basic) Authentication failure! Timeout::Error: Faraday::TimeoutError, Timeout::Error

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2025年七月16日 21:39 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/326 "2025-07-16T21:39:25Z")

</div>

🥳 此插件现已作为 [Bundling more popular plugins with Discourse core](https://meta.discourse.org/t/bundling-more-popular-plugins-with-discourse-core/373574?u=tobiaseigen) 的一部分，与 Discourse 核心捆绑在一起。如果您是自托管用户并使用了此插件，则需要在下次升级前将其从 `app.yml` 中移除。

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2025年七月24日 12:05 UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/330 "2025-07-24T12:05:06Z")

</div>

交叉引用

> [@Bundling more popular plugins with Discourse core](https://meta.discourse.org/t/bundling-more-popular-plugins-with-discourse-core/373574/58?u=david):
>
> If you’re on stable, then none of this topic will apply until after the next stable release in early August. So you should add oauth2-basic back to your app.yml. The original failure must have been for some other reason. Unfortunately the ‘hint’ logic is not very smart, and isn’t aware of stable vs. tests-passed.

[上一頁](https://meta.discourse.org/t/discourse-oauth2-basic/33879.md?page=1)
