Index: trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java	(revision 19637)
+++ trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java	(revision 19638)
@@ -263,5 +263,7 @@
                     return remembered;
                 }
-                return createDefault(apiUrl, oAuthVersion);
+                // Use the URL as it was given: apiUrl is the host by now, which is never a valid URL, so
+                // createDefault() would silently fall back to the API currently configured in the preferences.
+                return createDefault(originalApiUrl, oAuthVersion);
             default:
                 throw new IllegalArgumentException("Unknown OAuth version: " + oAuthVersion);
Index: trunk/src/org/openstreetmap/josm/io/OsmConnection.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 19637)
+++ trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 19638)
@@ -34,4 +34,5 @@
 import org.openstreetmap.josm.tools.JosmRuntimeException;
 import org.openstreetmap.josm.tools.Logging;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -147,4 +148,12 @@
      */
     private void obtainOAuth20Token() throws MissingOAuthAccessTokenException {
+        if (Utils.isEmpty(this.oAuth20Parameters.getClientId())) {
+            // Without a client id the authorization request is rejected by the server with "Missing required
+            // parameter: client_id", so do not send the user to the browser at all. The message of the exception
+            // is for the log only; what the user is shown already points at the preferences, which is where the
+            // client id of an OAuth application registered on this server has to be entered.
+            throw new MissingOAuthAccessTokenException(
+                    "No OAuth client id for " + OsmApi.getOsmApi().getServerUrl() + ", cannot request a token");
+        }
         if (!Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() ->
                 ConditionalOptionPaneUtil.showConfirmationDialog("oauth.oauth20.obtain.automatically",
@@ -201,5 +210,8 @@
     protected void addOAuth20AuthorizationHeader(HttpClient connection) throws OsmTransferException {
         if (this.oAuth20Parameters == null) {
-            this.oAuth20Parameters = OAuthParameters.createFromApiUrl(connection.getURL().getHost(), OAuthVersion.OAuth20);
+            // The parameters are stored under the API URL, so look them up with the API URL and not with the
+            // host of the request: OAuthParameters.createFromApiUrl() reduces it to the host itself where that
+            // is what it needs.
+            this.oAuth20Parameters = OAuthParameters.createFromApiUrl(OsmApi.getOsmApi().getServerUrl(), OAuthVersion.OAuth20);
         }
         OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
