האם תוסף oauth2-basic יכול להמיר טקסט ל-json?

סיכום מבוסס בינה מלאכותית

User qinyj reports an issue with the oauth2-basic plugin when attempting to log in via WeChat: the plugin expects a JSON response (application/json) but WeChat returns text/plain, causing authentication to fail. A screenshot shows successful Weibo login vs. failed WeChat login. qinyj provides a backtrace confirming the OAuth2 error. In post 7, qinyj offers a workaround for Chinese users: editing the oauth2 gem’s response.rb file to treat text/plain as :json — a fix specifically for WeChat, since it’s the only provider returning plain text. The user admits limited Ruby knowledge and seeks confirmation or official plugin updates.

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.

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?

here is the backtrace

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

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:

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

Change it to the following:

'text/plain' => :json,

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