[gnome-maps/wip/mlundblad/osm-oauth2: 2/2] WIP: Migrate to OAuth2 for OSM editing




commit 50d369e1221141afa7c776b011345e392bc2507a
Author: Marcus Lundblad <ml dfupdate se>
Date:   Sun Aug 21 00:57:33 2022 +0200

    WIP: Migrate to OAuth2 for OSM editing

 data/org.gnome.Maps.gschema.xml |  4 ++--
 lib/maps-osm-oauth-proxy-call.c |  6 +++---
 lib/maps-osm-oauth-proxy-call.h | 10 +++++-----
 org.gnome.Maps.json             |  6 +++---
 src/osmConnection.js            | 24 +++++++++++++-----------
 src/osmEdit.js                  |  6 +++---
 6 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/data/org.gnome.Maps.gschema.xml b/data/org.gnome.Maps.gschema.xml
index 2ed4ad61..91b7f24e 100644
--- a/data/org.gnome.Maps.gschema.xml
+++ b/data/org.gnome.Maps.gschema.xml
@@ -51,10 +51,10 @@
       <summary>Number of recent routes to store</summary>
       <description>Number of recently visited routes to store.</description>
     </key>
-    <key name="osm-username" type="s">
+    <key name="osm-username-oauth2" type="s">
       <default>""</default>
       <summary>OpenStreetMap username or e-mail address</summary>
-      <description>Indicates if the user has signed in to edit OpenStreetMap data.</description>
+      <description>Indicates if the user has signed in to edit OpenStreetMap data using OAith2.</description>
     </key>
     <key name="transportation-type" enum="org.gnome.maps.TransportationType">
       <default>'pedestrian'</default>
diff --git a/lib/maps-osm-oauth-proxy-call.c b/lib/maps-osm-oauth-proxy-call.c
index 5e9e7544..47359c60 100644
--- a/lib/maps-osm-oauth-proxy-call.c
+++ b/lib/maps-osm-oauth-proxy-call.c
@@ -33,7 +33,7 @@ struct _MapsOSMOAuthProxyCallPrivate
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE(MapsOSMOAuthProxyCall, maps_osm_oauth_proxy_call,
-                           OAUTH_TYPE_PROXY_CALL);
+                           REST_TYPE_OAUTH2_PROXY_CALL);
 
 static gboolean
 maps_osm_oauth_proxy_call_serialize_params (RestProxyCall *call,
@@ -85,9 +85,9 @@ maps_osm_oauth_proxy_call_init (MapsOSMOAuthProxyCall *call)
 }
 
 MapsOSMOAuthProxyCall *
-maps_osm_oauth_proxy_call_new (OAuthProxy *proxy, const char *payload)
+maps_osm_oauth_proxy_call_new (RestOAuth2Proxy *proxy, const char *payload)
 {
-  g_return_val_if_fail (OAUTH_IS_PROXY (proxy), NULL);
+  g_return_val_if_fail (REST_IS_OAUTH2_PROXY (proxy), NULL);
   g_return_val_if_fail (payload != NULL, NULL);
 
   MapsOSMOAuthProxyCall *call =
diff --git a/lib/maps-osm-oauth-proxy-call.h b/lib/maps-osm-oauth-proxy-call.h
index e9c240d8..03c6a363 100644
--- a/lib/maps-osm-oauth-proxy-call.h
+++ b/lib/maps-osm-oauth-proxy-call.h
@@ -22,8 +22,8 @@
 
 #include <glib-object.h>
 
-#include <rest/oauth-proxy-call.h>
-#include <rest/oauth-proxy.h>
+#include <rest/rest-oauth2-proxy-call.h>
+#include <rest/rest-oauth2-proxy.h>
 
 G_BEGIN_DECLS
 
@@ -40,17 +40,17 @@ typedef struct _MapsOSMOAuthProxyCallClass MapsOSMOAuthProxyCallClass;
 
 struct _MapsOSMOAuthProxyCall
 {
-  OAuthProxyCall parent;
+  RestOAuth2ProxyCall parent;
   MapsOSMOAuthProxyCallPrivate *priv;
 };
 
 struct _MapsOSMOAuthProxyCallClass
 {
-  OAuthProxyCallClass parent_class;
+  RestOAuth2ProxyCallClass parent_class;
 };
 
 GType maps_osm_oauth_proxy_call_get_type(void);
-MapsOSMOAuthProxyCall *maps_osm_oauth_proxy_call_new (OAuthProxy *proxy,
+MapsOSMOAuthProxyCall *maps_osm_oauth_proxy_call_new (RestOAuth2Proxy *proxy,
                                                       const char *content);
 
 G_END_DECLS
diff --git a/org.gnome.Maps.json b/org.gnome.Maps.json
index 35a27a54..9558cf4e 100644
--- a/org.gnome.Maps.json
+++ b/org.gnome.Maps.json
@@ -90,9 +90,9 @@
             ],
             "sources" : [
                 {
-                    "type" : "archive",
-                    "url" : "https://gitlab.gnome.org/GNOME/librest/-/archive/1.0.0/librest-1.0.0.tar.gz";,
-                    "sha256" : "eeba5ddbf91a29decec01c3ccce64b922bd9bf52d631e307e185227295aea51d"
+                    "type" : "git",
+                    "url" : "https://gitlab.gnome.org/GNOME/librest.git";,
+                    "branch": "master"
                 }
             ]
         },
diff --git a/src/osmConnection.js b/src/osmConnection.js
index 5a18f350..08f93965 100644
--- a/src/osmConnection.js
+++ b/src/osmConnection.js
@@ -38,8 +38,13 @@ const BASE_URL = 'https://api.openstreetmap.org/api';
 const API_VERSION = '0.6';
 
 /* OAuth constants */
-const CONSUMER_KEY = '2lbpDoED0ZspGssTBAJ8zOCtrtmUoX4KnmZUIWIK';
-const CONSUMER_SECRET = 'AO9BhDl9sJ33DjaZgQmYcNIuM3ZSml4xtugai6gE';
+const CLIENT_KEY = 'ATOMKAKOXQuAJXpFxkm__nDVRlJLYYmP-0P54UfDnZI';
+const CLIENT_SECRET = '9vda-8M_lt0cLJMLJlbTfJVRDGiS2-pPbeSNMRqBQ0k';
+const AUTH_URL = 'https://www.openstreetmap.org/oauth2/authorize';
+const ACCESS_TOKEN_URL = 'https://www.openstreetmap.org/oauth2/token';
+const REDIRECT_URL = 'urn:ietf:wg:oauth:2.0:oob';
+//const CONSUMER_KEY = '2lbpDoED0ZspGssTBAJ8zOCtrtmUoX4KnmZUIWIK';
+//const CONSUMER_SECRET = 'AO9BhDl9sJ33DjaZgQmYcNIuM3ZSml4xtugai6gE';
 const OAUTH_ENDPOINT_URL = 'https://www.openstreetmap.org/oauth';
 const LOGIN_URL = 'https://www.openstreetmap.org/login';
 
@@ -55,9 +60,10 @@ export class OSMConnection {
         this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version });
 
         /* OAuth proxy used for making OSM uploads */
-        this._callProxy = Rest.OAuthProxy.new(CONSUMER_KEY, CONSUMER_SECRET,
-                                              BASE_URL + '/' + API_VERSION,
-                                              false);
+        this._callProxy = Rest.OAuth2Proxy.new(AUTH_URL, ACCESS_TOKEN_URL,
+                                               REDIRECT_URL,
+                                               CLIENT_KEY, CLIENT_SECRET,
+                                               BASE_URL + '/' + API_VERSION);
         GnomeMaps.osm_init();
     }
 
@@ -93,7 +99,7 @@ export class OSMConnection {
            OAuth access token enrolled, so, if the currently instantiated
            proxy instance doesn't have a token set, we could safely count on
            it being present in the keyring */
-        if (this._callProxy.get_token() === null) {
+        if (this._callProxy.get_access_token() === null) {
             Secret.password_lookup(SECRET_SCHEMA, {}, null, (s, res) => {
                 this._onPasswordLookedUp(res,
                                          comment,
@@ -108,11 +114,7 @@ export class OSMConnection {
         let password = Secret.password_lookup_finish(result);
 
         if (password) {
-            let token = password.split(':')[0];
-            let secret = password.split(':')[1];
-
-            this._callProxy.token = token;
-            this._callProxy.token_secret = secret;
+            this._callProxy.access_token = password;
             this._doOpenChangeset(comment, callback);
         } else {
             callback(false, null, null);
diff --git a/src/osmEdit.js b/src/osmEdit.js
index 16f41741..b7004a3c 100644
--- a/src/osmEdit.js
+++ b/src/osmEdit.js
@@ -34,7 +34,7 @@ export class OSMEdit {
     constructor() {
         this._osmConnection = new OSMConnection();
         this._osmObject = null; // currently edited object
-        this._username = Application.settings.get('osm-username');
+        this._username = Application.settings.get('osm-username-oauth2');
         this._isSignedIn = this._username !== null && this._username.length > 0;
     }
 
@@ -164,7 +164,7 @@ export class OSMEdit {
                  * username to signify that we are signed in
                  */
                 this._username = username ?? '_unknown_';
-                Application.settings.set('osm-username', this._username);
+                Application.settings.set('osm-username-oauth2', this._username);
                 callback(true);
             });
         } else {
@@ -176,7 +176,7 @@ export class OSMEdit {
         this._username = null;
         this._isSignedIn = false;
 
-        Application.settings.set('osm-username', '');
+        Application.settings.set('osm-username-oauth2', '');
         this._osmConnection.signOut();
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]