# Can plugin oauth2-basic convert text to json?

**URL:** https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618
**Category:** SSO
**Tags:** oauth2
**Created:** [August 30, 2022, 5:35pm UTC](https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618 "2022-08-30T17:35:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![qinyj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/qinyj/32/204391_2.png) [@qinyj](https://meta.discourse.org/u/qinyj)
#### Post date: [August 30, 2022, 5:35pm UTC](https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618/1 "2022-08-30T17:35:16Z")

</div>

To log in with WECHAT account, I tried to use plugin oatuh2-basic but meet a problem.

Usually, WECHAT server should return `applicaion/json`, then the plugin can read USID in the json string.

Unfortunatly, the server just return `text/plain`, which cannot be read by the plugin.

Here is the result. One has logged in with WEIBO successfully, and the other one tried to login in with WECHAT but failed.

 ![微信截图_20220831005805](https://global.discourse-cdn.com/meta/original/4X/e/a/2/ea2e6aa163fc81482064af3909ea7b5a2f87d7e3.png)

I tried to modify the plugin’s code but failed, cause I have no idea how to deal with ruby language.

So can someone tell me where the code should be edited? Or is there any possibility that the plugin could be updated?

---

<div class="post-metadata">

### Author: ![qinyj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/qinyj/32/204391_2.png) [@qinyj](https://meta.discourse.org/u/qinyj)
#### Post date: [August 31, 2022, 4:01pm UTC](https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618/4 "2022-08-31T16:01:49Z")

</div>

here is the backtrace

```plaintext
Message

(oauth2_basic) Authentication failure! invalid_credentials: OAuth2::Error, {"access_token":"60_xf-0xS4znmnu9z-2ZDhNN40RRluErfbiThzzoDz9p8-Ki9pH-A3ML2n3q6UhT7D6d6iCXlEVS5B7kGFsnhW2JHq6eXHNWOgzqXqMsAvhfY4","expires_in":7200,"refresh_token":"60_gfsBHpp0btOnWaZpnRXMywNTzDURCymRtw8sQj21XXC99aebh58Mb4vBGiKaXdYqDGkdovn2ytFoiqavsSWHLt_UiExbkPYA0z-4DBVjDlA","openid":"o01u45oBVM2YbPzmxXau263z_iW4","scope":"snsapi_base"}

Backtrace

/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:163:in `log'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:486:in `fail!'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-oauth2-1.7.2/lib/omniauth/strategies/oauth2.rb:96:in `rescue in callback_phase'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-oauth2-1.7.2/lib/omniauth/strategies/oauth2.rb:84:in `callback_phase'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:238:in `callback_call'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:189:in `call!'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:169:in `call'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:192:in `call!'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:169:in `call'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:192:in `call!'

Env

HTTP HOSTS: frps.southdog.cool

```

---

<div class="post-metadata">

### Author: ![qinyj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/qinyj/32/204391_2.png) [@qinyj](https://meta.discourse.org/u/qinyj)
#### Post date: [September 8, 2022, 4:24pm UTC](https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618/7 "2022-09-08T16:24:48Z")

</div>

Show Chinese compatriots a way forward. In the container ` /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.7/lib/oauth2/response.rb`, the following code exists:

```plaintext
    # Content type assignments for various potential HTTP content types.
    @@content_types = {
      'application/json' => :json,
      ………………
      'text/plain' => :text,
    }

```

Change it to the following:

```plaintext
'text/plain' => :json,

```

Of course, this should only be useful for WeChat, as only WeChat returns text.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 8, 2022, 4:24pm UTC](https://meta.discourse.org/t/can-plugin-oauth2-basic-convert-text-to-json/237618/8 "2022-10-08T16:24:55Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
