zorn-v / nextcloud-social-login

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

Custom Oauth2 Mismatching Redirect URI #300

Closed SidSidSid16 closed 2 years ago

SidSidSid16 commented 2 years ago

I have a Django app that acts as an Oauth2 provider and I'm trying to add Nextcloud as a client.

www.example.com => Oauth2 Provider (Django app) cloud.example.com => Nextcloud

Django Configuration Redirection URI: https://cloud.example.com/index.php/apps/sociallogin/custom_oauth2/WM Client Type: confidential Authorization Grant Type: authorization-code

Social Login Configuration Internal name: WM API Base URL: https://www.example.com/o/ Authorize URL: https://www.example.com/o/authorize/ Token URL: https://www.example.com/o/token/ Profile URL: https://www.example.com/o/resources/user Logout URL: Scope: read Profile Fields: username Groups claim:

Now when trying to log in, the login form from the Django app shows, and after I enter my username and password my Django app returns an error stating "Error: Invalid request, Mismatching redirect URI."

The URL looks like this:

https://www.example.com/o/authorize/?response_type=code&client_id=bni6NhReCjDoZs3wx2xKW2IUlgkbh6Ajh6etWmAN&redirect_uri=http%3A%2F%2Fcloud.examplecom%2Fapps%2Fsociallogin%2Fcustom_oauth2%2FWM&scope=read&state=HA-AM1VUP2NY6WILDC8QGXR70E3K4ZFTHBJS9O5

With the redirect URL: http%3A%2F%2Fcloud.examplecom%2Fapps%2Fsociallogin%2Fcustom_oauth2%2FWM&scope=read&state=HA-AM1VUP2NY6WILDC8QGXR70E3K4ZFTHBJS9O5

I noticed that the redirect URL that is set in the Django app is HTTPS and the one that this Social Login App returns in HTTP, changing the Django app to HTTP gives the same error.

But the biggest thing that grabbed my attention is that the URL that the Social Login App returns haven't been properly decoded, for example with %3A%2F%2F instead of ://

How do I fix this?

SidSidSid16 commented 2 years ago

Turns out I missed that the URLs are different.

After fixing this, I am no longer getting the URI mismatch error, However, I am getting a different error. I have created another issue for this (#301)