Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osmApi: use OAuth 2.0 #235

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/featureLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
};
27 changes: 10 additions & 17 deletions src/services/osmApiAuth.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) =>
Expand Down
34 changes: 4 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading