Skip to content

Commit

Permalink
use OAuth 2.0 instead of 1.0a for OpenStreetMap (#2348)
Browse files Browse the repository at this point in the history
closes #2293
  • Loading branch information
Changaco authored Apr 29, 2024
1 parent 916bef5 commit fea9bb9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion liberapay/elsewhere/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Platform:
required_attrs = ('account_url', 'display_name', 'name')

def __init__(self, api_key, api_secret, callback_url, api_url=None, auth_url=None,
api_timeout=20.0, app_name=None, app_url=None):
api_timeout=20.0, app_name=None, app_url=None, access_token_url=None):
self.api_key = api_key
self.api_secret = api_secret
self.callback_url = callback_url
Expand All @@ -108,6 +108,8 @@ def __init__(self, api_key, api_secret, callback_url, api_url=None, auth_url=Non
self.auth_url = auth_url
elif not getattr(self, 'auth_url', None):
self.auth_url = self.api_url
if access_token_url:
self.access_token_url = access_token_url
self.api_timeout = api_timeout
self.app_name = app_name
self.app_url = app_url
Expand Down
9 changes: 6 additions & 3 deletions liberapay/elsewhere/openstreetmap.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from liberapay.elsewhere._base import PlatformOAuth1
from liberapay.elsewhere._base import PlatformOAuth2
from liberapay.elsewhere._extractors import not_available, xpath


class OpenStreetMap(PlatformOAuth1):
class OpenStreetMap(PlatformOAuth2):

# Platform attributes
name = 'openstreetmap'
display_name = 'OpenStreetMap'
account_url = 'http://www.openstreetmap.org/user/{user_name}'

# API attributes
# Auth attributes - https://wiki.openstreetmap.org/wiki/OAuth
oauth_default_scope = ['read_prefs']

# API attributes - https://wiki.openstreetmap.org/wiki/API_v0.6
api_format = 'xml'
api_user_info_path = '/user/{user_id}'
api_user_self_info_path = '/user/details'
Expand Down
1 change: 1 addition & 0 deletions liberapay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class AppConf:
linuxfr_id=str,
linuxfr_secret=str,
log_emails=bool,
openstreetmap_access_token_url=str,
openstreetmap_api_url=str,
openstreetmap_auth_url=str,
openstreetmap_callback=str,
Expand Down
9 changes: 5 additions & 4 deletions sql/app-conf-defaults.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ INSERT INTO app_conf (key, value) VALUES
('linuxfr_id', '"c574b5f45ce054a0750a3764b3ff8ff2c9f88fe36611272a0bf5e4e07bd3c0bf"'::jsonb),
('linuxfr_secret', '"8c518595790487015cd0c33be2d04939946f99aad33c86a6af20a99bc749fb3b"'::jsonb),
('log_emails', 'true'::jsonb),
('openstreetmap_api_url', '"https://api.openstreetmap.org/api/0.6"'::jsonb),
('openstreetmap_auth_url', '"https://www.openstreetmap.org"'::jsonb),
('openstreetmap_access_token_url', '"https://master.apis.dev.openstreetmap.org/oauth2/token"'::jsonb),
('openstreetmap_api_url', '"https://master.apis.dev.openstreetmap.org/api/0.6"'::jsonb),
('openstreetmap_auth_url', '"https://master.apis.dev.openstreetmap.org/oauth2/authorize"'::jsonb),
('openstreetmap_callback', '"http://127.0.0.1:8339/on/openstreetmap/associate"'::jsonb),
('openstreetmap_id', '"w4eQbkobmMzpkJFwS4tM16a3lq9AFbcoNCKNcGBE"'::jsonb),
('openstreetmap_secret', '"W08UgEhxQnh7nMzB7GfSFcqcwPnZMmKMNyxWdcw4"'::jsonb),
('openstreetmap_id', '"xAVaXxy0BwUef4SIo55v7E1ofuC53EN8H-X5232d8Vo"'::jsonb),
('openstreetmap_secret', '"JtqazsotvWZQ1G6ynYhDlHXouQji-qDwwU2WQW7j-kE"'::jsonb),
('password_rounds', '1'::jsonb),
('payday_repo', '"liberapay-bot/test"'::jsonb),
('payday_label', '"Payday"'::jsonb),
Expand Down
5 changes: 5 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INSERT INTO app_conf VALUES ('openstreetmap_access_token_url', '"https://master.apis.dev.openstreetmap.org/oauth2/token"') ON CONFLICT (key) DO NOTHING;
UPDATE app_conf SET value = '"https://master.apis.dev.openstreetmap.org/api/0.6"' WHERE key = 'openstreetmap_api_url';
UPDATE app_conf SET value = '"https://master.apis.dev.openstreetmap.org/oauth2/authorize"' WHERE key = 'openstreetmap_auth_url';
UPDATE app_conf SET value = '"xAVaXxy0BwUef4SIo55v7E1ofuC53EN8H-X5232d8Vo"' WHERE key = 'openstreetmap_id';
UPDATE app_conf SET value = '"JtqazsotvWZQ1G6ynYhDlHXouQji-qDwwU2WQW7j-kE"' WHERE key = 'openstreetmap_secret';

0 comments on commit fea9bb9

Please sign in to comment.