Skip to content

Commit

Permalink
npm run build
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd authored and bhousel committed Oct 23, 2023
1 parent 4fcbe21 commit cce3ba0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
60 changes: 40 additions & 20 deletions dist/osm-auth.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ function osmAuth(o) {
return;
}
oauth.logout();
_generatePkceChallenge(function(pkce) {
_authenticate(pkce, callback);
_preopenPopup(function(error, popup) {
if (error) {
callback(error);
} else {
_generatePkceChallenge(function(pkce) {
_authenticate(pkce, popup, callback);
});
}
});
};
oauth.authenticateAsync = function() {
Expand All @@ -66,10 +72,40 @@ function osmAuth(o) {
resolve(result);
}
};
_generatePkceChallenge((pkce) => _authenticate(pkce, errback));
_preopenPopup((error, popup) => {
if (error) {
errback(error);
} else {
_generatePkceChallenge((pkce) => _authenticate(pkce, popup, errback));
}
});
});
};
function _authenticate(pkce, callback) {
function _preopenPopup(callback) {
if (o.singlepage) {
callback(null, void 0);
return;
}
var w = 550;
var h = 610;
var settings = [
["width", w],
["height", h],
["left", window.screen.width / 2 - w / 2],
["top", window.screen.height / 2 - h / 2]
].map(function(x) {
return x.join("=");
}).join(",");
var popup = window.open("about:blank", "oauth_window", settings);
if (popup) {
callback(null, popup);
} else {
var error = new Error("Popup was blocked");
error.status = "popup-blocked";
callback(error);
}
}
function _authenticate(pkce, popup, callback) {
var state = generateState();
var url = o.url + "/oauth2/authorize?" + utilQsString({
client_id: o.client_id,
Expand All @@ -96,24 +132,8 @@ function osmAuth(o) {
window.location = url;
}
} else {
var w = 600;
var h = 550;
var settings = [
["width", w],
["height", h],
["left", window.screen.width / 2 - w / 2],
["top", window.screen.height / 2 - h / 2]
].map(function(x) {
return x.join("=");
}).join(",");
var popup = window.open("about:blank", "oauth_window", settings);
oauth.popupWindow = popup;
popup.location = url;
if (!popup) {
error = new Error("Popup was blocked");
error.status = "popup-blocked";
callback(error);
}
}
window.authComplete = function(url2) {
var params2 = utilStringQs(url2.split("?")[1]);
Expand Down
Loading

0 comments on commit cce3ba0

Please sign in to comment.