nextcloud / user_external

👥 External user authentication methods like IMAP, SMB and FTP
https://apps.nextcloud.com/apps/user_external
107 stars 64 forks source link

Authentication issue with BasicAuth and external URL #239

Open ludovicsclain opened 8 months ago

ludovicsclain commented 8 months ago

Hey there,

I'm trying to use user_external plugin with BasicAuth authentication to authenticate users of my NextCloud instance via external API (Flask). However, I encounter an issue where NextCloud returns the error: "ERROR: Mis-configured BasicAuth Url: [my_url], provided URL does not do authentication!".

Here's what I've done so far:

I have configured my Flask API to return a WWW-Authenticate header when credentials are not provided. When valid credentials are provided, my Flask API queries my WordPress site to verify those credentials. If the credentials are valid, the API returns an HTTP status code 200. Otherwise, it returns a 403 code. I've verified that my Flask API works as expected using Postman and other tools. However, when I try to log in via NextCloud, I get the error mentioned above.

I also looked at the plugin code and found that the error is triggered when the WWW-Authenticate header is not found in my API response. However, my logs clearly show that this header is present.

Has anyone encountered this problem before or could help me debug this situation? Any help would be greatly appreciated.

Thanks in advance.

Steps to reproduce

  1. Set up the user_external app with BasicAuth pointing to an external Flask API for authentication.
  2. The Flask API checks credentials against a WordPress site.
  3. Try to log in to Nextcloud using valid WordPress credentials.

Expected behaviour

Successful authentication and access to Nextcloud.

Actual behaviour

Receiving error: "ERROR: Mis-configured BasicAuth Url: [my_url], provided URL does not do authentication!".

Affected Authentication backend

BasicAuth with an external Flask API.

Server configuration

User External App version: 3.2.0

Operating system: Linux

Web server: (Your web server type, e.g., Apache, Nginx)

Database: Type: mysql, Version: 8.0.31

PHP version: Version: 7.4.32

Nextcloud version: 25.0.10

Logs

Nextcloud log (data/nextcloud.log)

Nextcloud log ``` {"reqId":"ZS1CV7EPZtBue9XU-1eGoAAAADw","level":3,"time":"2023-10-16T14:01:59+00:00","remoteAddr":"111.11.11.111","user":"--","app":"user_external","method":"POST","url":"/login","message":"ERROR: Mis-configured BasicAuth Url: https://monapi/nextcloud-auth, provided URL does not do authentication!","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","version":"25.0.10.1","data":{"app":"user_external"}} {"reqId":"ZS1CV7EPZtBue9XU-1eGoAAAADw","level":2,"time":"2023-10-16T14:01:59+00:00","remoteAddr":"111.11.11.111","user":"--","app":"no app in context","method":"POST","url":"/login","message":"Login failed: xxxxxxx.xxxxx@gmail.com (Remote IP: xxx.xx.xx.xxx)","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","version":"25.0.10.1","data":[]} ```