Skip to content

Commit

Permalink
Switch to OAuth 2.0 (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlant committed Mar 16, 2024
1 parent 7e9a014 commit 8b43082
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 51 deletions.
44 changes: 5 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"leaflet.locatecontrol": "^0.79.0",
"normalize.css": "^8.0.1",
"opening_hours": "^3.8.0",
"osm-auth": "^1.1.0",
"osm-auth": "^2.4.0",
"osm-parking-tag-updater": "github:osmberlin/osm-tag-updater",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
25 changes: 14 additions & 11 deletions src/utils/osm-client.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import * as JXON from 'jxon'
import osmAuth from 'osm-auth'
import { osmAuth } from 'osm-auth'
import { osmProdUrl, osmDevUrl } from './links'

import { type OsmWay } from './types/osm-data'
import { type ChangedIdMap, type ChangesStore, type JxonOsmWay } from './types/changes-store'

let auth: OSMAuth.OSMAuthInstance | null = null
let auth: OSMAuth.osmAuth | null = null

function craeteOsmAuth(useDevServer: boolean) {
return useDevServer ?
// Used to not have these new keywords
// eslint-disable-next-line new-cap
new osmAuth({
url: osmDevUrl,
oauth_consumer_key: 'FhbDyU5roZ0wAPffly1yfiYChg8RaNuFlJTB0SE1',
oauth_secret: 'gTzuFDWUqmZnwho2NIaVoxpgSX47Xyqq65lTw8do',
client_id: 'lX6vX5gKHEfLV9kybjRpy2L7BTqtwZ5c_G7sjKscVw0',
access_token: localStorage.getItem('https://master.apis.dev.openstreetmap.orgoauth2_access_token') ?? undefined,
redirect_uri: window.location.origin + window.location.pathname + 'land.html',
scope: 'read_prefs write_api',
auto: true,
}) :
// eslint-disable-next-line new-cap
new osmAuth({
url: osmProdUrl,
oauth_consumer_key: 'Np0gmfYoqo6Ronla4wuFTXEUgypODL0jPRzjiFW6',
oauth_secret: 'KnUDQ3sL3T7LZjvwi5OJj1hxNBz0UiSpTr0T0fLs',
client_id: 'wwP2hKLF5LAWQgZTcd8SjYXsCzd8zYvl7muuQm1V3Jo',
access_token: localStorage.getItem('https://openstreetmap.orgoauth2_access_token') ?? undefined,
redirect_uri: window.location.origin + window.location.pathname + 'land.html',
scope: 'read_prefs write_api',
auto: true,
})
}
Expand Down Expand Up @@ -65,7 +68,7 @@ export function userInfo(): Promise<any> {
return osmXhr({
method: 'GET',
path: '/api/0.6/user/details',
options: { header: { Accept: 'application/json' } },
headers: { Accept: 'application/json' },
})
}

Expand Down Expand Up @@ -122,7 +125,7 @@ function createChangeset(editorName: string, editorVersion: string): Promise<str
return osmXhr({
method: 'PUT',
path: '/api/0.6/changeset/create',
options: { header: { 'Content-Type': 'text/xml' } },
headers: { 'Content-Type': 'text/xml' },
content: JXON.jsToString(change),
})
}
Expand All @@ -146,7 +149,7 @@ function saveChangesets(changesStore: ChangesStore, changesetId: string, editorN
return osmXhr({
method: 'POST',
path: '/api/0.6/changeset/' + changesetId + '/upload',
options: { header: { 'Content-Type': 'text/xml' } },
headers: { 'Content-Type': 'text/xml' },
content: JXON.jsToString(change),
})
}
Expand All @@ -155,7 +158,7 @@ function closeChangeset(changesetId: string) {
return osmXhr({
method: 'PUT',
path: '/api/0.6/changeset/' + changesetId + '/close',
options: { header: { 'Content-Type': 'text/xml' } },
headers: { 'Content-Type': 'text/xml' },
})
}

Expand Down

0 comments on commit 8b43082

Please sign in to comment.