QField icon indicating copy to clipboard operation
QField copied to clipboard

[BUG] The `7070` port of the redirect URL is replaced by `0` when trying to connect (4G-LTE) to an OAuth2 WFS service: oauthlib error raised. QField 3.0.7 (35e3ee)

Open nicolas-sitylb opened this issue 1 year ago • 0 comments

Describe the issue

When trying to connect to a WFS service (provided by a GeoMapFish instance using an OAuth2 connection, it seems that the port (7070) of the redirect URL is replaced by 0. Indeed, it tries to reach http://127.0.0.1:0/ instead of http://127.0.0.1:7070/ (this last URL being the one configured in the QGIS project) therefore, the server throws an internal server error when receiving that URL:

Error handling request /login?type=oauth2&response_type=code&client_id=***********************&redirect_uri=http%3A%2F%2F127.0.0.1%3A0%2F

... GeoMapFish python Traceback ...

   File "/opt/c2cgeoportal/geoportal/c2cgeoportal_geoportal/views/login.py", line 227, in _oauth2_login
     headers, body, status = oauth2.get_oauth_client(
   File "/usr/local/lib/python3.8/dist-packages/oauthlib/oauth2/rfc6749/endpoints/base.py", line 112, in wrapper
     return f(endpoint, uri, *args, **kwargs)
   File "/usr/local/lib/python3.8/dist-packages/oauthlib/oauth2/rfc6749/endpoints/authorization.py", line 100, in create_authorization_response
     return response_type_handler.create_authorization_response(
   File "/usr/local/lib/python3.8/dist-packages/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py", line 244, in create_authorization_response
     self.validate_authorization_request(request)
   File "/usr/local/lib/python3.8/dist-packages/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py", line 367, in validate_authorization_request
     self._handle_redirects(request)
   File "/usr/local/lib/python3.8/dist-packages/oauthlib/oauth2/rfc6749/grant_types/base.py", line 242, in _handle_redirects
     raise errors.MismatchingRedirectURIError(request=request)
 oauthlib.oauth2.rfc6749.errors.MismatchingRedirectURIError: (invalid_request) Mismatching redirect URI. <oauthlib.Request SANITIZED>

The same problem occurs when setting a different port (e.g. 80, 443, or other values) in the redirect URL parameter of the OAuth2 authentication tab: it consistently tries to reach http://127.0.0.1:0/ instead of the specified port.

Reproduction steps

Steps to reproduce the behavior:

  1. Select a local QGIS project file having a WFS connection using an OAuth2 authentication
  2. It opens a mini web browser to connect to the OAuth2 web service
  3. Enter credentials (username+password)
  4. Encounter "Internal Server Error" when the login button is clicked

Expected behavior

It should be redirected to the following URL, which is the proper one (it's working with QGIS Desktop 3.22.16): https://server.ch/login?type=oauth2&response_type=code&client_id=***********************&redirect_uri=http%3A%2F%2F127.0.0.1%3A7070%2F

Observed behavior

See "Describe the issue" above.

Mobile (please complete the following information)

  • Device: HAPPY-TAB-8_V1.1
  • OS: Android 10 (the problem doesn't seem to appear on Android 9 / Samsung phone)
  • QField version: 3.0.7 (35e3ee)

Additional information

  • Problem started happening recently, didn't happen in an older version of QField: N/A
  • Problem can be reliably reproduced, doesn't happen randomly: ~YES: it mostly occurs when connected using 4G (LTE)
  • Problem happens with all files and projects, not only some files or projects: YES

I was not able to find out a debug tool or a developer toolbox that can capture some events or messages inside QField before loading a project. This would be great to help debugging such early issue.

Thanks for your precious support and all the nice job done on QField.

nicolas-sitylb avatar Nov 28 '23 11:11 nicolas-sitylb