mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 17:14:04 +02:00
Upgrade to osm-auth v2 which uses OAuth2 to connect to OSM API
This commit is contained in:
committed by
Martin Raifer
parent
e4ed585ce4
commit
6058f89460
+19
-16
@@ -2,26 +2,30 @@ import _throttle from 'lodash-es/throttle';
|
||||
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { json as d3_json, xml as d3_xml } from 'd3-fetch';
|
||||
|
||||
import osmAuth from 'osm-auth';
|
||||
import { osmAuth } from 'osm-auth';
|
||||
import RBush from 'rbush';
|
||||
|
||||
import { JXON } from '../util/jxon';
|
||||
import { geoExtent, geoRawMercator, geoVecAdd, geoZoomToScale } from '../geo';
|
||||
import { osmEntity, osmNode, osmNote, osmRelation, osmWay } from '../osm';
|
||||
import { utilArrayChunk, utilArrayGroupBy, utilArrayUniq, utilRebind, utilTiler, utilQsString } from '../util';
|
||||
import { utilArrayChunk, utilArrayGroupBy, utilArrayUniq, utilObjectOmit, utilRebind, utilTiler, utilQsString } from '../util';
|
||||
|
||||
|
||||
var tiler = utilTiler();
|
||||
var dispatch = d3_dispatch('apiStatusChange', 'authLoading', 'authDone', 'change', 'loading', 'loaded', 'loadedNotes');
|
||||
|
||||
var urlroot = 'https://www.openstreetmap.org';
|
||||
var redirectPath = window.location.origin + window.location.pathname;
|
||||
var oauth = osmAuth({
|
||||
url: urlroot,
|
||||
oauth_consumer_key: '5A043yRSEugj4DJ5TljuapfnrflWDte8jTOcWLlT',
|
||||
oauth_secret: 'aB3jKq1TRsCOUrfOIZ6oQMEDmv2ptV76PA54NGLL',
|
||||
client_id: 'O3g0mOUuA2WY5Fs826j5tP260qR3DDX7cIIE2R2WWSc',
|
||||
client_secret: 'b4aeHD1cNeapPPQTrvpPoExqQRjybit6JBlNnxh62uE',
|
||||
scope: 'read_prefs write_prefs write_api read_gpx write_notes',
|
||||
redirect_uri: redirectPath + 'land.html',
|
||||
loading: authLoading,
|
||||
done: authDone
|
||||
});
|
||||
|
||||
// hardcode default block of Google Maps
|
||||
var _imageryBlocklists = [/.*\.google(apis)?\..*\/(vt|kh)[\?\/].*([xyz]=.*){3}.*/];
|
||||
var _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() };
|
||||
@@ -785,7 +789,7 @@ export default {
|
||||
var options = {
|
||||
method: 'PUT',
|
||||
path: '/api/0.6/changeset/create',
|
||||
options: { header: { 'Content-Type': 'text/xml' } },
|
||||
headers: { 'Content-Type': 'text/xml' },
|
||||
content: JXON.stringify(changeset.asJXON())
|
||||
};
|
||||
_changeset.inflight = oauth.xhr(
|
||||
@@ -806,7 +810,7 @@ export default {
|
||||
var options = {
|
||||
method: 'POST',
|
||||
path: '/api/0.6/changeset/' + changesetID + '/upload',
|
||||
options: { header: { 'Content-Type': 'text/xml' } },
|
||||
headers: { 'Content-Type': 'text/xml' },
|
||||
content: JXON.stringify(changeset.osmChangeJXON(changes))
|
||||
};
|
||||
_changeset.inflight = oauth.xhr(
|
||||
@@ -832,7 +836,7 @@ export default {
|
||||
oauth.xhr({
|
||||
method: 'PUT',
|
||||
path: '/api/0.6/changeset/' + changeset.id + '/close',
|
||||
options: { header: { 'Content-Type': 'text/xml' } }
|
||||
headers: { 'Content-Type': 'text/xml' }
|
||||
}, function() { return true; });
|
||||
}
|
||||
}
|
||||
@@ -1267,14 +1271,13 @@ export default {
|
||||
},
|
||||
|
||||
|
||||
switch: function(options) {
|
||||
urlroot = options.urlroot;
|
||||
switch: function(newOptions) {
|
||||
urlroot = newOptions.url;
|
||||
|
||||
oauth.options(Object.assign({
|
||||
url: urlroot,
|
||||
loading: authLoading,
|
||||
done: authDone
|
||||
}, options));
|
||||
// Copy the existing options, but omit 'access_token'.
|
||||
// (if we did preauth, access_token won't work on a different server)
|
||||
var oldOptions = utilObjectOmit(oauth.options(), 'access_token');
|
||||
oauth.options(Object.assign(oldOptions, newOptions));
|
||||
|
||||
this.reset();
|
||||
this.userChangesets(function() {}); // eagerly load user details/changesets
|
||||
@@ -1384,7 +1387,7 @@ export default {
|
||||
that.userChangesets(function() {}); // eagerly load user details/changesets
|
||||
}
|
||||
|
||||
return oauth.authenticate(done);
|
||||
oauth.authenticate(done);
|
||||
},
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user