From fadc4783e80e3530e01cff2b1646f8355b20f380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zbytovsk=C3=BD?= Date: Sun, 11 Feb 2024 09:28:33 +0100 Subject: [PATCH] osmApi: use OAuth 2.0 --- package.json | 2 +- src/helpers/featureLabel.ts | 4 ++-- src/services/osmApiAuth.ts | 27 ++++++++++----------------- yarn.lock | 34 ++++------------------------------ 4 files changed, 17 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index 884b8af24..0deef5b08 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "next": "^13.4.3", "next-cookies": "^2.0.3", "next-pwa": "^5.2.21", - "osm-auth": "^1.1.1", + "osm-auth": "^2.4.0", "react": "^18.2.0", "react-custom-scrollbars": "^4.2.1", "react-dom": "^18.2.0", diff --git a/src/helpers/featureLabel.ts b/src/helpers/featureLabel.ts index 68538f3a1..6f0a732fa 100644 --- a/src/helpers/featureLabel.ts +++ b/src/helpers/featureLabel.ts @@ -8,7 +8,7 @@ export const getSubclass = ({ layer, osmMeta, properties, schema }: Feature) => (layer && layer.id) || // layer.id specified only when maplibre-gl skeleton displayed osmMeta.type; -const getRef = (feature: Feature) => +const getRefLabel = (feature: Feature) => feature.tags.ref ? `${getSubclass(feature)} ${feature.tags.ref}` : ''; const getName = ({ tags }: Feature) => tags.name; // TODO choose a name according to locale @@ -24,5 +24,5 @@ export const getLabel = (feature: Feature) => { return roundedToDeg(roundedCenter); } - return getName(feature) || getRef(feature) || getSubclass(feature); + return getName(feature) || getRefLabel(feature) || getSubclass(feature); }; diff --git a/src/services/osmApiAuth.ts b/src/services/osmApiAuth.ts index 1f2a19927..fd5ad1ebd 100644 --- a/src/services/osmApiAuth.ts +++ b/src/services/osmApiAuth.ts @@ -1,6 +1,6 @@ import escape from 'lodash/escape'; -import OsmAuth from 'osm-auth'; import getConfig from 'next/config'; +import { osmAuth } from 'osm-auth'; import { Feature, FeatureTags, Position } from './types'; import { buildXmlString, @@ -9,37 +9,30 @@ import { getUrlOsmId, OsmApiId, parseXmlString, - prod, + // prod, stringifyDomXml, } from './helpers'; import { join } from '../utils'; import { clearFeatureCache } from './osmApi'; +import { isBrowser } from '../components/helpers'; const { publicRuntimeConfig: { osmappVersion }, } = getConfig(); +const prod = true; const osmEditUrl = prod ? 'https://www.openstreetmap.org' // iD uses same URL https://ideditor.netlify.app/ : 'https://master.apis.dev.openstreetmap.org'; - -const oauth = prod - ? { - oauth_consumer_key: 'OGIlDMpqYIRA35NBggNFNnRBftlWdJt4eE2z7eFb', - oauth_secret: '37V3dRzWYfdnRrG8L8vaKyzs6A191HkRtXlaqNH9', - } - : { - // https://master.apis.dev.openstreetmap.org/changeset/1599 - oauth_consumer_key: 'eWdvGfVsTdhRCGtwRkn4qOBaBAIuVNX9gTX63TUm', - oauth_secret: 'O0UXzrNbpFkbIVB0rqumhMSdqdC1wa9ZFMpPUBYG', - }; const TEST_OSM_ID = { type: 'node', id: '967531' }; // https://master.apis.dev.openstreetmap.org/node/967531 -const auth = new OsmAuth({ - ...oauth, +// TS file in osm-auth is probably broken (new is required) +// @ts-ignore +const auth = osmAuth({ + client_id: 'vWUdEL3QMBCB2O9q8Vsrl3i2--tcM34rKrxSHR9Vg68', + redirect_uri: isBrowser() && `${window.location.origin}/oauth-token.html`, + scope: 'read_prefs write_api write_notes openid', auto: true, - landing: '/oauth-token.html', - url: osmEditUrl, }); const authFetch = async (options) => diff --git a/yarn.lock b/yarn.lock index 6675bc961..b24126ede 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5111,11 +5111,6 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA== -jshashes@~1.0.8: - version "1.0.8" - resolved "https://registry.yarnpkg.com/jshashes/-/jshashes-1.0.8.tgz#f60d837428383abf73ab022e1542e6614bd75514" - integrity sha512-btmQZ/w1rj8Lb6nEwvhjM7nBYoj54yaEFo2PWh3RkxZ8qNwuvOxvQYN/JxVuwoMmdIluL+XwYVJ+pEEZoSYybQ== - json-parse-better-errors@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" @@ -5909,13 +5904,6 @@ object.values@^1.1.4: define-properties "^1.1.3" es-abstract "^1.18.2" -ohauth@~1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/ohauth/-/ohauth-1.0.1.tgz#a5d4ab8e5390bb1cad68a58cc9c58630173c02f2" - integrity sha512-R9ZUN3+FVCwzeOOHCJpzA9jw/byRxp5O9X06mTL6Sp/LIQn/rLrMv6cwYctX+hoIKzRUsalGJXZ1kG5wBmSskQ== - dependencies: - jshashes "~1.0.8" - once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -5959,14 +5947,10 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" -osm-auth@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/osm-auth/-/osm-auth-1.1.1.tgz#2a6be41fb45998d9276b879154f8b86628de17d7" - integrity sha512-U2Q7wvjcLJSi7P1a4JKIgTSvWlVq2rqCsjYLHX/cMeIuiMDM8y0B/LQCQyvM7KKJa1juk3Do35dhlwPGxtxc/Q== - dependencies: - ohauth "~1.0.1" - resolve-url "~0.2.1" - store "~2.0.12" +osm-auth@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/osm-auth/-/osm-auth-2.4.0.tgz#d77a0c17ce985b867902871186b71fd32a21f731" + integrity sha512-FvTyYnIl+pjLi9cKJWNM74PjrLUED1f2TnWpAexxJ2qoxr8sdndON/EzXHf0nfMLB07Pn9DPyWVEbTXZ/nID8A== p-each-series@^2.1.0: version "2.2.0" @@ -6532,11 +6516,6 @@ resolve-protobuf-schema@^2.1.0: dependencies: protocol-buffers-schema "^3.3.1" -resolve-url@~0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" - integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= - resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.20.0: version "1.20.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" @@ -6938,11 +6917,6 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" -store@~2.0.12: - version "2.0.12" - resolved "https://registry.yarnpkg.com/store/-/store-2.0.12.tgz#8c534e2a0b831f72b75fc5f1119857c44ef5d593" - integrity sha1-jFNOKguDH3K3X8XxEZhXxE711ZM= - streamsearch@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"