Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebDAV authentication not working with Nextcloud 27 #255

Open
klasyc opened this issue Dec 5, 2023 · 11 comments
Open

WebDAV authentication not working with Nextcloud 27 #255

klasyc opened this issue Dec 5, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@klasyc
Copy link

klasyc commented Dec 5, 2023

Hello,

I am trying to configure Nextcloud 27 to authenticate against Keycloak 23 for development purposes. I run both applications inside docker containers, the Nextcloud is a clean nextcloud:latest docker image with nextcloud-oidc-login app installed. Web authentication works as expected, but I am not able to get the WebDAV authentication working.

I enabled the WebDAV authentication in the config.php:

'oidc_login_webdav_enabled' => true,
'oidc_login_password_authentication' => true,

And now I am trying to use the basic WebDAV authentication via curl:

curl --request OPTIONS -v --user "vojtech:vojtech" http://localhost:9001/remote.php/dav/files/vojtech

I am getting error 401 for my Keycloak user, but the request succeeds for the admin user, which has a native Nextcloud account.

To investigate further, I checked if the BasicAuthBackend::handle() method correctly registers the OIDC backend, but I found out that the initial event check fails because the event is of class OCP\SabrePluginEvent and not the \OCA\DAV\Events\SabrePluginAuthInitEvent in my case. Therefore, the OIDC backend is not registered at all and authentication, of course, fails.

Then I tried to comment out the type check, but I finished with the following exception:

OCA\OIDCLogin\Provider\OpenIDConnectClient::getTokenProfile(): Return value must be of type array, stdClass returned.

I checked the JWT passed to the getTokenProfile() method, and it is valid according to jwt.io. Since the exception is thrown by the decodeJWT() method which comes from the 3rd party library, it seems like some kind of interface incompatibility...

Could you help me to troubleshoot the WebDAV authentication?

@pulsejet
Copy link
Owner

pulsejet commented Dec 8, 2023

Can you try removing the return type of getTokenProfile? YOu may need to restart the php server after this to clear the opcache.

@klasyc
Copy link
Author

klasyc commented Dec 8, 2023

I had to remove:

  • Type check at lib/WebDAV/BasicAuthBackend.php line 75 (already mentioned above).
  • Return type at lib/Provider/OpenIDConnectClient.php::getTokenProfile().
  • Type of the first parameter of the lib/Service/LoginService.php::login() function.
  • Type of the first parameter of the lib/Service/LoginService.php::flatten() function.

Then the basic authentication for WebDAV started to work.

After removing the same type check at lib/WebDAV/BearerAuthBackend.php line 76 also the Bearer authentication started to work.

pulsejet added a commit that referenced this issue Dec 8, 2023
@pulsejet
Copy link
Owner

pulsejet commented Dec 8, 2023

Thanks for helping debug this. Can you revert your changes (just uninstall / re-install the app maybe) and test this patch?
ac62355

@klasyc
Copy link
Author

klasyc commented Dec 12, 2023

Hi, I re-created the docker container and applied your patch. Basic authorization works fine, but bearer token does not work - I always get error 401.

@pulsejet
Copy link
Owner

Does removing the type check in bearerauthbackend fix this? Maybe the event is something else...

@klasyc
Copy link
Author

klasyc commented Dec 12, 2023

No, it does not help. Perhaps there is some issue in the token validation...

@pulsejet
Copy link
Owner

That's .. weird. That commit changed nothing related to tokens

@klasyc
Copy link
Author

klasyc commented Dec 14, 2023

After the next round of testing, I finally got it working. Your patch was OK, but my access token was not. The iss and aud fields had wrong values because of bad Keycloak configuration. Unfortunately, the server did not give me helpful error messages, which made me think the plugin is broken... Could you turn your commit into a new release?

@vlntnpprwrk
Copy link

vlntnpprwrk commented Dec 30, 2023

+1, do you think this fix will be turned into a release soon ?
Got the same problem with WebDAV login since Nextcloud 27 upgrade

@pulsejet
Copy link
Owner

pulsejet commented Jan 5, 2024

3.0.2 is up

@azmeuk azmeuk added the bug Something isn't working label Apr 11, 2024
@SpiderD555
Copy link

I have just made a test with 3.0.2 sitting on Nextcloud 28.0.4 and Authentik 2024.2.3 along with app password - tested with Joplin. I can confirm it works, although the app password for now is limited in duration to 30 minutes until the next release of Authentik 2024.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants