Skip to content

Commit

Permalink
Support separate urls for OAuth handshake and OSM API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Oct 24, 2023
1 parent cce3ba0 commit b42ca40
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ var redirectPath = window.location.origin + window.location.pathname;
Additional options are:

- `access_token` - Can pre-authorize with an OAuth2 bearer token if you have one
- `url` - A base url (default: "https://www.openstreetmap.org")
- `apiUrl` - A base url for the OSM API (default: "https://api.openstreetmap.org")
- `url` - A base url for the OAuth2 handshake (default: "https://www.openstreetmap.org")
- `auto` - If `true`, attempt to authenticate automatically when calling `.xhr()` or `fetch()` (default: `false`)
- `singlepage` - If `true`, use page redirection instead of a popup (default: `false`)
- `loading` - Function called when auth-related xhr calls start
Expand Down Expand Up @@ -269,4 +270,4 @@ Options (getter / setter)<br/>
<br/>
Param: `val?` Object containing options<br/>
Return: current `options` (if getting), or `self` (if setting)<br/>
<br/>
<br/>
3 changes: 2 additions & 1 deletion dist/osm-auth.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function osmAuth(o) {
}
}
function _doXHR() {
var url = options.prefix !== false ? o.url + options.path : options.path;
var url = options.prefix !== false ? o.apiUrl + options.path : options.path;
return oauth.rawxhr(
options.method,
url,
Expand Down Expand Up @@ -289,6 +289,7 @@ function osmAuth(o) {
if (!arguments.length)
return o;
o = val;
o.apiUrl = o.apiUrl || "https://api.openstreetmap.org";
o.url = o.url || "https://www.openstreetmap.org";
o.auto = o.auto || false;
o.singlepage = o.singlepage || false;
Expand Down
4 changes: 2 additions & 2 deletions dist/osm-auth.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/osm-auth.iife.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/osm-auth.iife.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/osm-auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export function osmAuth(o) {
}

function _doXHR() {
var url = options.prefix !== false ? (o.url + options.path) : options.path;
var url = options.prefix !== false ? (o.apiUrl + options.path) : options.path;
return oauth.rawxhr(
options.method,
url,
Expand Down Expand Up @@ -455,6 +455,7 @@ export function osmAuth(o) {
if (!arguments.length) return o;

o = val;
o.apiUrl = o.apiUrl || 'https://api.openstreetmap.org';
o.url = o.url || 'https://www.openstreetmap.org';
o.auto = o.auto || false;
o.singlepage = o.singlepage || false;
Expand Down Expand Up @@ -621,4 +622,4 @@ function base64(buffer) {
.replace(/\//g, '_')
.replace(/\+/g, '-')
.replace(/[=]/g, '');
}
}
3 changes: 3 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('osmauth', t => {
localStorage.clear();
const keys = {
url: 'https://www.openstreetmap.org',
apiUrl: 'https://api.openstreetmap.org',
client_id: 'JWXSAzNp64sIRMStTnkhMRaMxSR964V4sFgn3KUZNTA',
client_secret: '6umOXfkZqH5CVUtv6iDqN7k8o7mKbQvTrHvbDQH36hs',
redirect_uri: 'http://127.0.0.1:8080/land.html',
Expand All @@ -32,6 +33,7 @@ test('osmauth', t => {
localStorage.clear();
const auth = osmAuth({
url: 'https://www.openstreetmap.org',
apiUrl: 'https://api.openstreetmap.org',
client_id: 'JWXSAzNp64sIRMStTnkhMRaMxSR964V4sFgn3KUZNTA',
redirect_uri: 'http://127.0.0.1:8080/land.html',
scope: 'read_prefs'
Expand All @@ -44,6 +46,7 @@ test('osmauth', t => {
localStorage.clear();
const auth = osmAuth({
url: 'https://www.openstreetmap.org',
apiUrl: 'https://api.openstreetmap.org',
client_id: 'JWXSAzNp64sIRMStTnkhMRaMxSR964V4sFgn3KUZNTA',
redirect_uri: 'http://127.0.0.1:8080/land.html',
scope: 'read_prefs',
Expand Down

0 comments on commit b42ca40

Please sign in to comment.