froger-me/wp-weixin

Tocken authentication fail

alexlii1971 opened this issue · 16 comments

Hello,

https://wordpress.org/support/topic/white-page-upon-saving-setting/

The above issue was fixed with your latest update.

I tried to have a test in a subsite of our multisite, but it show the token authentication fail, when I follow the this instructions:

"https://test.mysite.com/weixin-responder" in https://mp.weixin.qq.com/ under Development > Basic configuration.

I am sure I input WeChat AES Key and WeChat Token, and FYR, screenshot at http://prntscr.com/kywrp3

Alex

Hey @alexlii1971 ! Thank you for the heads up regarding the WordPress issue - I'll close it right away.

Just to make sure, did you verify your domain with the MP_verify_[code_redacted].txt file from WeChat?

I just checked the token validation again on my test install successfully, so I'm thinking it may be an issue of configuration rather than code.

Hi

Yes, I already upload it before, please check the screenshot of FTP:

http://prntscr.com/kyye8w

and actually, Both WeChat login and WeChat payment are working on my site already by other plugin,

Should I input domain of test site into business and JS domain in WeChat? whether it is a must setting?
Anyway, I already input it, but still failed.

Thanks.

I see - good it's out of the way.
What do you get when visiting https://test.mysite.com/weixin-responder in a browser?

You should see a blank screen with a simple line "wuut?" (it will change to a proper 401 error in a next version).

Edit: the JS settings are not needed if what you're only looking for is using the responder - so this should not be the cause.

Another thing I can think of: the Web Page Authorization settings.
You need to set "Business domain name" and "Webpage authorization domain name".

In Chinese: "网页授权", "设置 业务域名", "网页授权域名".

Hi
I already set that, but still fail

How about the other question above, regarding visiting the responder URL?

it just show 404 page, and I think the key issue is that token authitication fail at wechat backend.

Then that's the issue.
Please clear you permalinks by visiting https://test.mysite.com/wp-admin/options-permalink.php and try again.

@alexlii1971 Any news? I would really like to make sure your issue is resolved ASAP.

Sorry, I missed your last two posts.

What do you mean by "Clear your permalinks"?

Anyway, I change permalink setting from archives/id to postname, please check the screenshot:

http://prntscr.com/l07nii

but still I got 404 page at frontend:

http://prntscr.com/l07nx2

and also failed for token auth at WeChat backend.

Thanks for the screenshots, and no worries - I mean ASAP for you ;).

Simply visiting the permalinks page should be enough to clear them, so it seems it did its job. What I fail to understand is why the https://test.mysite.com/weixin-responder gives you a 404 error.

This 404 error is the reason why the token authentication fails in the WeChat backend. WeChat needs to communicate with https://test.mysite.com/weixin-responder, and when it hits the 404, it rejects the configuration.

All I can think of right now is a possible conflict with another plugin, because adding the weixin-responder endpoint is a pretty basic piece of code - it's simply a call to add_rewrite_rule in a init action hook, and catching the request in a parse_request action hook. Very simple. But if some other plugins, or the theme, interfere with these hooks, it could cause issues.

One way that does not involve coding would be to try to use the default theme and test, and if that doesn't work, disabling plugins one by one and test at each step to identify the source. Then if you tell me where the conflict disappeared, I could test with the culprit plugin or theme and solve the issue.

If it is not possible (for example if the website has tons of widgets and/or is on production mode), if you know how to do WordPress development, I can walk you step by step and tell you where to put multiple PHP error_log to perform a backtrace - then you'd report the result, and I could see how to do the adjustments. Otherwise it seems the only remaining solution for us to investigate would be for me to have access to the code base on the server used to do the tests (and I am aware it requires trust).

To sum up, I see 3 solutions to move forward:

  • theme/plugin deactivation, with tests for possible conflicts at each step, with report
  • error_log backtrace with report
  • letting me have access to the code base via SSH and the WordPress backend for me to test

I deactivate all plugin in network, and only keep wp-weixin activated in a subsite with twenty-seven theme:

http://prntscr.com/l0bi5o

as screenshot showing, it still show 404 page, so, I just assume it is not compatible with multisite, and it actually not work now, what do you think?

if you know how to do WordPress development, I can walk you step by step and tell you where to put multiple PHP error_log to perform a backtrace - then you'd report the result, and I could see how to do the adjustments.

I am not technical background, but I can use FTP or simple SSH command to manage site, FYI, our site is working and carried on EE https://easyengine.io, I am not sure your backtrace code work with it.

anyway, I would like to have a try with you.

letting me have access to the code base via SSH and the WordPress backend for me to test.

BTW, are you in Beijing now? if yes, I think we might get to meet and have a cup of coffee if you like.

Hi @alexlii1971 !
I've been thinking about the multisite compatibility issue, by actually checking how add_rewrite_rule behaves in that case, and it confirms what I thought: multisite or not, it should behave the same in our case.

I thought about 2 other things:

  • Did you visit https://test.mysite.com/wp-admin/options-permalink.php after deactivating the plugins and theme? This is necessary to remove the possible extra rules set up by plugins and themes that could have conflicted.
  • Do you have any extra rules in the .htaccess file, besides the ones WordPress adds by default? There could be something that bypasses the rewrite done at the WordPress level.

Regarding troubleshooting with a backtrace, as long as we have access to the server's php error logs file, this is possible. The first step could be to add the following code to wp-includes/class-wp-rewrite.php on line 1601:

error_log( 'Extra rules top: ' . print_r( $this->extra_rules_top, true ) );

With the latest version of WP Weixin activated and Responder enabled, the output should look like:

Extra rules top: Array
(
// Some other rules here
    [^wp-weixin/get-qrcode/hash/(.*)$] => index.php?__wp_weixin_api=1&action=get-qrcode&hash=$matches[1]
    [^wp-weixin/wechat-auth$] => index.php?__wp_weixin_api=1&action=wechat-auth
    [^wp-weixin/wechat-auth-qr/hash/(.*)$] => index.php?__wp_weixin_api=1&action=wechat-auth-qr&hash=$matches[1]
    [^wp-weixin/wechat-auth-validate/hash/(.*)$] => index.php?__wp_weixin_api=1&action=wechat-auth-validate&hash=$matches[1]
    [^weixin-responder] => index.php?__wp_weixin_api=1&action=responder
// Some other rules here  
)

Yes, I am in Beijing! Could you add me on WeChat scanning this QR code? We could definitely spend some time checking that around a cup of coffee!

HI

Did you visit https://test.mysite.com/wp-admin/options-permalink.php after deactivating the plugins and theme? This is necessary to remove the possible extra rules set up by plugins and themes that could have conflicted.

Yes.

Do you have any extra rules in the .htaccess file, besides the ones WordPress adds by default? There could be something that bypasses the rewrite done at the WordPress level.

we are using Nginx, as for as I know, there is no such special rules.

I input the following line at 1601 as screenshot:http://prntscr.com/l0g80e, if it is not right, please correct me.
error_log( 'Extra rules top: ' . print_r( $this->extra_rules_top, true ) );

Since we are using Easyengine, and I need enable debug log, would you please check this page, and let me know which error log I should enable please: https://easyengine.io/docs/commands/debug/

With the latest version of WP Weixin activated and Responder enabled, the output should look like:
I just guess you mean those output will be shown on wp-weixin setting page at the backend of test site, right? if yes, I do not found that info at both backend and front page at https://work.mysite.com/weixin-responder, also I cleared permalink.php.

also I check the setting at backend of WeChat basic configuration, the token auth still fail.

Alex

Was an error in the rewrites - fixed

Was an error in the rewrites - fixed

Hi,

I face the same error regarding the token, and after reading, I'm in the same situation.

token验证失败

or translated : Token verification failed

could you please develop the solution regarding the rewrites ?

Thank you very much,
Theo