python-social-auth / social-core

Python Social Auth - Core
BSD 3-Clause "New" or "Revised" License
851 stars 545 forks source link

Addressing URL Flexibility in OpenStreetMap and others apps base in OSM software #893

Open Rub21 opened 8 months ago

Rub21 commented 8 months ago

There are some initiatives that use OpenStreetMap software, such as OpenHistoricalMap. This module has been used by OSMCha, which is part of the OpenStreetMap and OpenHistoricalMap ecosystem. However, since the URL is hardcoded only for OSM.

https://github.com/python-social-auth/social-core/blob/master/social_core/backends/openstreetmap.py#L43

I am facing some errors when I log in using OpenHistoricalMap. Could the URLs be passed in an environment variable, or could there be an option to do that?

Internal Server Error: /api/v1/social-auth/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/social_core/utils.py", line 251, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/social_core/backends/oauth.py", line 191, in do_auth
    data = self.user_data(access_token)
  File "/usr/local/lib/python3.10/site-packages/social_core/backends/openstreetmap.py", line 40, in user_data
    response = self.oauth_request(
  File "/usr/local/lib/python3.10/site-packages/social_core/backends/oauth.py", line 298, in oauth_request
    return self.request(url, method=method, params=params,
  File "/usr/local/lib/python3.10/site-packages/social_core/backends/base.py", line 234, in request
    response.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openstreetmap.org/api/0.6/user/details

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/app/osmchadjango/users/views.py", line 125, in post
    return Response(self.get_user_token(request, access_token))
  File "/app/osmchadjango/users/views.py", line 100, in get_user_token
    user = backend.do_auth(access_token, user=authed_user)
  File "/usr/local/lib/python3.10/site-packages/social_core/utils.py", line 256, in wrapper
    raise AuthForbidden(args[0])

cc. @willemarcel

mmd-osm commented 8 months ago

NB: https://github.com/python-social-auth/social-core/blob/master/social_core/backends/openstreetmap.py#L43 uses the now deprecated OAuth 1.0a. Please switch to the OAuth 2.0 version instead, which is available here: https://github.com/python-social-auth/social-core/blob/master/social_core/backends/openstreetmap_oauth2.py