zorn-v / nextcloud-social-login

GNU Affero General Public License v3.0
198 stars 137 forks source link

Custom oauth2 fails with Error 405 #385

Closed beerlao closed 1 year ago

beerlao commented 1 year ago

I'm trying to connect Mailcow (https://docs.mailcow.email/third_party/nextcloud/third_party-nextcloud/) with Nexcloud using social login. This has been working for a year, but I recently moved Nextcloud to a different server. Since then I'm unable to login via oauth2. Frontend error in Nextcloud:

Unable to exchange code for API access token. HTTP error 405. Raw Provider API response: .

HTTP Session:

https://pastebin.com/ENbM6eNY

Nextcloud is running as fpm on docker behind an nginx proxy. NGINX log:

2a02:8071:xxxx:xxxxx:xxxx:xxxx:xxxx:xxxx - - [02/Jan/2023:18:10:43 +0000] "GET /apps/sociallogin/custom_oauth2/Mailcow HTTP/2.0" 302 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0" 2a02:8071:xxxx:xxxx:xxxx:xxxx:xxxx - - [02/Jan/2023:18:10:45 +0000] "GET /apps/sociallogin/custom_oauth2/Mailcow?code=73f3c1e878a941fef00362f640239ceef284139a&state=HA-3I7B5VZFN8GC0WS1MRUAJLX2T46Q9EHKOPDY HTTP/2.0" 401 3932 "https://mailcow.xxx.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0"

Any help highly appreciated, thanks!

zorn-v commented 1 year ago

405 - is "method not allowed" (e.g. GET instead of POST). It returns from mailcow. Can you remember what version of nextcloud was when all works and now ?

beerlao commented 1 year ago

405 - is "method not allowed" (e.g. GET instead of POST). It returns from mailcow. Can you remember what version of nextcloud was when all works and now ?

The version didn't change, 25.0.2. I wonder why neither nginx in front of Mailcow nor nginx in front of Nextcloud throws a 405, but a 401 (as you can see on pastebin). Any clue how I could debug this on Nextcloud's end?

zorn-v commented 1 year ago

401 returns from nextcloud plugin because mailcow return something unexpected (empty response with 405 status) Here https://github.com/zorn-v/nextcloud-social-login/blob/fd94346c0685d16e6dea099967e7333d52c95d60/3rdparty/hybridauth/hybridauth/src/Adapter/OAuth2.php#L514-L521

beerlao commented 1 year ago

401 returns from nextcloud plugin because mailcow return something unexpected (empty response with 405 status) Here

https://github.com/zorn-v/nextcloud-social-login/blob/fd94346c0685d16e6dea099967e7333d52c95d60/3rdparty/hybridauth/hybridauth/src/Adapter/OAuth2.php#L514-L521

Thanks a lot. I'm not really deep into PHP, but I can try to debug. Would you mind have a look at the HTTP request? Could it be an issue between HTTP/1.0 and HTTP/2.0?

Mailcow:

[03/Jan/2023:15:20:20 +0100] "GET /oauth/authorize?response_type=code&client_id=008084b445be&redirect_uri=https%3A%2F%2Fnc.xxx.net%2Fapps%2Fsociallogin%2Fcustom_oauth2%2FMailcow&scope=profile&state=HA-7PTRAMV4H05U2E6LGBCI1OYZ93KXNWFJ8SQD HTTP/1.0" 200 181628 "-"
[03/Jan/2023:15:20:20 +0100] "GET /api/v1/get/passwordpolicy/html HTTP/1.0" 200 81
[03/Jan/2023:15:20:21 +0100] "POST /oauth/authorize?response_type=code&client_id=008084b445be&redirect_uri=https%3A%2F%2Fnc.xxx.net%2Fapps%2Fsociallogin%2Fcustom_oauth2%2FMailcow&scope=profile&state=HA-7PTRAMV4H05U2E6LGBCI1OYZ93KXNWFJ8SQD HTTP/1.0" 302 0

Nextcloud:

[03/Jan/2023:14:20:20 +0000] "GET /apps/sociallogin/custom_oauth2/Mailcow HTTP/2.0" 302 0
[03/Jan/2023:14:20:21 +0000] "GET /apps/sociallogin/custom_oauth2/Mailcow?code=361a57aeee33aa1d403d74f187f001b
84cd7870a&state=HA-7PTRAMV4H05U2E6LGBCI1OYZ93KXNWFJ8SQD HTTP/2.0" 401 3932
zorn-v commented 1 year ago

Last POST request to mailcow is redirected (302). Redirect and POST is something weird :)

beerlao commented 1 year ago

Last POST request to mailcow is redirected (302). Redirect and POST is something weird :)

Indeed! Thanks, I'll try to dig deeper there and will report :-)

beerlao commented 1 year ago

Was a misconfiguration on my side. Thanks for your help, very much appreciated! Closing this now.