Index: /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 9352)
@@ -15,4 +15,5 @@
 import java.net.Authenticator.RequestorType;
 import java.net.PasswordAuthentication;
+import java.util.concurrent.Executor;
 
 import javax.swing.AbstractAction;
@@ -67,4 +68,5 @@
     private JPanel pnlActionButtonsPanel;
     private JPanel pnlResult;
+    private final Executor executor;
 
     /**
@@ -296,8 +298,10 @@
      * Constructs a new {@code FullyAutomaticAuthorizationUI} for the given API URL.
      * @param apiUrl The OSM API URL
+     * @param executor the executor used for running the HTTP requests for the authorization
      * @since 5422
      */
-    public FullyAutomaticAuthorizationUI(String apiUrl) {
+    public FullyAutomaticAuthorizationUI(String apiUrl, Executor executor) {
         super(apiUrl);
+        this.executor = executor;
         build();
     }
@@ -327,5 +331,5 @@
         @Override
         public void actionPerformed(ActionEvent evt) {
-            Main.worker.submit(new FullyAutomaticAuthorisationTask(FullyAutomaticAuthorizationUI.this));
+            executor.execute(new FullyAutomaticAuthorisationTask(FullyAutomaticAuthorizationUI.this));
         }
 
@@ -377,5 +381,5 @@
         @Override
         public void actionPerformed(ActionEvent arg0) {
-            Main.worker.submit(new TestAccessTokenTask(
+            executor.execute(new TestAccessTokenTask(
                     FullyAutomaticAuthorizationUI.this,
                     getApiUrl(),
Index: /trunk/src/org/openstreetmap/josm/gui/oauth/ManualAuthorizationUI.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/oauth/ManualAuthorizationUI.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/oauth/ManualAuthorizationUI.java	(revision 9352)
@@ -12,4 +12,5 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.concurrent.Executor;
 
 import javax.swing.AbstractAction;
@@ -23,5 +24,4 @@
 import javax.swing.text.JTextComponent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.oauth.OAuthToken;
 import org.openstreetmap.josm.gui.SideButton;
@@ -47,4 +47,5 @@
     private JCheckBox cbSaveToPreferences;
     private HtmlPanel pnlMessage;
+    private final Executor executor;
 
     protected JPanel buildAccessTokenPanel() {
@@ -163,8 +164,10 @@
      * Constructs a new {@code ManualAuthorizationUI} for the given API URL.
      * @param apiUrl The OSM API URL
+     * @param executor the executor used for running the HTTP requests for the authorization
      * @since 5422
      */
-    public ManualAuthorizationUI(String apiUrl) {
+    public ManualAuthorizationUI(String apiUrl, Executor executor) {
         super(apiUrl);
+        this.executor = executor;
         build();
     }
@@ -261,5 +264,5 @@
                     getAccessToken()
             );
-            Main.worker.submit(task);
+            executor.execute(task);
         }
 
Index: /trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java	(revision 9352)
@@ -22,4 +22,5 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.concurrent.Executor;
 
 import javax.swing.AbstractAction;
@@ -44,4 +45,5 @@
 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
 import org.openstreetmap.josm.gui.help.HelpUtil;
+import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.gui.widgets.HtmlPanel;
@@ -49,4 +51,5 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.OpenBrowser;
+import org.openstreetmap.josm.tools.UserCancelException;
 import org.openstreetmap.josm.tools.WindowGeometry;
 
@@ -65,4 +68,20 @@
     private ManualAuthorizationUI pnlManualAuthorisationUI;
     private JScrollPane spAuthorisationProcedureUI;
+    private final Executor executor;
+
+    /**
+     * Launches the wizard, {@link OAuthAccessTokenHolder#setAccessToken(OAuthToken) sets the token}
+     * and {@link OAuthAccessTokenHolder#setSaveToPreferences(boolean) saves to preferences}.
+     * @throws UserCancelException if user cancels the operation
+     */
+    public void showDialog() throws UserCancelException {
+        setVisible(true);
+        if (isCanceled()) {
+            throw new UserCancelException();
+        }
+        OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
+        holder.setAccessToken(getAccessToken());
+        holder.setSaveToPreferences(isSaveAccessTokenToPreferences());
+    }
 
     /**
@@ -170,7 +189,7 @@
         this.setMinimumSize(new Dimension(600, 420));
 
-        pnlFullyAutomaticAuthorisationUI = new FullyAutomaticAuthorizationUI(apiUrl);
-        pnlSemiAutomaticAuthorisationUI = new SemiAutomaticAuthorizationUI(apiUrl);
-        pnlManualAuthorisationUI = new ManualAuthorizationUI(apiUrl);
+        pnlFullyAutomaticAuthorisationUI = new FullyAutomaticAuthorizationUI(apiUrl, executor);
+        pnlSemiAutomaticAuthorisationUI = new SemiAutomaticAuthorizationUI(apiUrl, executor);
+        pnlManualAuthorisationUI = new ManualAuthorizationUI(apiUrl, executor);
 
         spAuthorisationProcedureUI = GuiHelper.embedInVerticalScrollPane(new JPanel());
@@ -209,22 +228,14 @@
      * Creates the wizard.
      *
-     * @param apiUrl the API URL. Must not be null.
-     * @throws IllegalArgumentException if apiUrl is null
-     */
-    public OAuthAuthorizationWizard(String apiUrl) {
-        this(Main.parent, apiUrl);
-    }
-
-    /**
-     * Creates the wizard.
-     *
      * @param parent the component relative to which the dialog is displayed
      * @param apiUrl the API URL. Must not be null.
+     * @param executor the executor used for running the HTTP requests for the authorization
      * @throws IllegalArgumentException if apiUrl is null
      */
-    public OAuthAuthorizationWizard(Component parent, String apiUrl) {
+    public OAuthAuthorizationWizard(Component parent, String apiUrl, Executor executor) {
         super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL);
         CheckParameterUtil.ensureParameterNotNull(apiUrl, "apiUrl");
         this.apiUrl = apiUrl;
+        this.executor = executor;
         build();
     }
Index: /trunk/src/org/openstreetmap/josm/gui/oauth/SemiAutomaticAuthorizationUI.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/oauth/SemiAutomaticAuthorizationUI.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/oauth/SemiAutomaticAuthorizationUI.java	(revision 9352)
@@ -14,4 +14,5 @@
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.util.concurrent.Executor;
 
 import javax.swing.AbstractAction;
@@ -21,5 +22,4 @@
 import javax.swing.JPanel;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.oauth.OAuthToken;
 import org.openstreetmap.josm.gui.SideButton;
@@ -47,5 +47,6 @@
     private RetrieveAccessTokenPanel pnlRetrieveAccessToken;
     private ShowAccessTokenPanel pnlShowAccessToken;
-
+    private final Executor executor;
+    
     /**
      * build the UI
@@ -63,8 +64,10 @@
      * Constructs a new {@code SemiAutomaticAuthorizationUI} for the given API URL.
      * @param apiUrl The OSM API URL
+     * @param executor the executor used for running the HTTP requests for the authorization
      * @since 5422
      */
-    public SemiAutomaticAuthorizationUI(String apiUrl) {
+    public SemiAutomaticAuthorizationUI(String apiUrl, Executor executor) {
         super(apiUrl);
+        this.executor = executor;
         build();
     }
@@ -396,5 +399,5 @@
                     getAdvancedPropertiesPanel().getAdvancedParameters()
             );
-            Main.worker.submit(task);
+            executor.execute(task);
             Runnable r  = new Runnable() {
                 @Override
@@ -411,5 +414,5 @@
                 }
             };
-            Main.worker.submit(r);
+            executor.execute(r);
         }
     }
@@ -433,5 +436,5 @@
                     requestToken
             );
-            Main.worker.submit(task);
+            executor.execute(task);
             Runnable r  = new Runnable() {
                 @Override
@@ -448,5 +451,5 @@
                 }
             };
-            Main.worker.submit(r);
+            executor.execute(r);
         }
     }
@@ -471,5 +474,5 @@
                     getAccessToken()
             );
-            Main.worker.submit(task);
+            executor.execute(task);
         }
     }
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java	(revision 9352)
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.gui.help.HelpUtil;
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
+import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
 
@@ -57,5 +58,6 @@
         gc.anchor = GridBagConstraints.NORTHWEST;
         gc.fill = GridBagConstraints.HORIZONTAL;
-        gc.weightx = 0.0;
+        gc.gridx = 1;
+        gc.weightx = 1.0;
         gc.insets = new Insets(0, 0, 0, 3);
         add(rbBasicAuthentication = new JRadioButton(), gc);
@@ -65,6 +67,6 @@
 
         //-- radio button for OAuth
-        gc.gridx = 1;
-        gc.weightx = 1.0;
+        gc.gridx = 0;
+        gc.weightx = 0.0;
         add(rbOAuth = new JRadioButton(), gc);
         rbOAuth.setText(tr("Use OAuth"));
@@ -118,5 +120,5 @@
      */
     public final void initFromPreferences() {
-        String authMethod = Main.pref.get("osm-server.auth-method", "basic");
+        final String authMethod = OsmApi.getAuthMethod();
         if ("basic".equals(authMethod)) {
             rbBasicAuthentication.setSelected(true);
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java	(revision 9352)
@@ -35,4 +35,5 @@
 import org.openstreetmap.josm.io.auth.CredentialsManager;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.UserCancelException;
 
 /**
@@ -325,11 +326,12 @@
             OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
                     OAuthAuthenticationPreferencesPanel.this,
-                    apiUrl
-            );
-            wizard.setVisible(true);
-            if (wizard.isCanceled()) return;
-            OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
-            holder.setAccessToken(wizard.getAccessToken());
-            holder.setSaveToPreferences(wizard.isSaveAccessTokenToPreferences());
+                    apiUrl,
+                    Main.worker);
+            try {
+                wizard.showDialog();
+            } catch (UserCancelException ignore) {
+                Main.trace(ignore.toString());
+                return;
+            }
             pnlAdvancedProperties.setAdvancedParameters(wizard.getOAuthParameters());
             refreshView();
@@ -340,5 +342,5 @@
      * Launches the OAuthAuthorisationWizard to generate a new Access Token
      */
-    private class RenewAuthorisationAction extends AbstractAction {
+    private class RenewAuthorisationAction extends AuthoriseNowAction {
         /**
          * Constructs a new {@code RenewAuthorisationAction}.
@@ -348,20 +350,4 @@
             putValue(SHORT_DESCRIPTION, tr("Click to step through the OAuth authorization process and generate a new Access Token"));
             putValue(SMALL_ICON, ImageProvider.get("oauth", "oauth-small"));
-
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent arg0) {
-            OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
-                    OAuthAuthenticationPreferencesPanel.this,
-                    apiUrl
-            );
-            wizard.setVisible(true);
-            if (wizard.isCanceled()) return;
-            OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
-            holder.setAccessToken(wizard.getAccessToken());
-            holder.setSaveToPreferences(wizard.isSaveAccessTokenToPreferences());
-            pnlAdvancedProperties.setAdvancedParameters(wizard.getOAuthParameters());
-            refreshView();
         }
     }
Index: /trunk/src/org/openstreetmap/josm/io/OsmApi.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 9352)
@@ -582,6 +582,14 @@
      * @since 6349
      */
-    public static final boolean isUsingOAuth() {
-        return "oauth".equals(Main.pref.get("osm-server.auth-method", "basic"));
+    public static boolean isUsingOAuth() {
+        return "oauth".equals(getAuthMethod());
+    }
+
+    /**
+     * Returns the authentication method set in the preferences
+     * @return the authentication method
+     */
+    public static String getAuthMethod() {
+        return Main.pref.get("osm-server.auth-method", "oauth");
     }
 
Index: /trunk/src/org/openstreetmap/josm/io/OsmConnection.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 9352)
@@ -4,5 +4,8 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.lang.reflect.InvocationTargetException;
 import java.net.Authenticator.RequestorType;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
@@ -10,7 +13,11 @@
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.oauth.OAuthParameters;
+import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
 import org.openstreetmap.josm.io.auth.CredentialsAgentException;
@@ -22,4 +29,7 @@
 import oauth.signpost.OAuthConsumer;
 import oauth.signpost.exception.OAuthException;
+import org.openstreetmap.josm.tools.Utils;
+
+import javax.swing.SwingUtilities;
 
 /**
@@ -96,6 +106,10 @@
         OAuthConsumer consumer = oauthParameters.buildConsumer();
         OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
-        if (!holder.containsAccessToken())
+        if (!holder.containsAccessToken()) {
+            obtainAccessToken(connection);
+        }
+        if (!holder.containsAccessToken()) { // check if wizard completed
             throw new MissingOAuthAccessTokenException();
+        }
         consumer.setTokenWithSecret(holder.getAccessTokenKey(), holder.getAccessTokenSecret());
         try {
@@ -106,6 +120,41 @@
     }
 
+    /**
+     * Obtains an OAuth access token for the connection. Afterwards, the token is accessible via {@link OAuthAccessTokenHolder}.
+     * @param connection connection for which the access token should be obtained
+     * @throws MissingOAuthAccessTokenException if the process cannot be completec successfully
+     */
+    protected void obtainAccessToken(final HttpClient connection) throws MissingOAuthAccessTokenException {
+        try {
+            final URL apiUrl = new URL(Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL));
+            if (!Objects.equals(apiUrl.getHost(), connection.getURL().getHost())) {
+                throw new MissingOAuthAccessTokenException();
+            }
+            final Runnable authTask = new FutureTask<>(new Callable<OAuthAuthorizationWizard>() {
+                @Override
+                public OAuthAuthorizationWizard call() throws Exception {
+                    // Concerning Utils.newDirectExecutor: Main.worker cannot be used since this connection is already
+                    // executed via Main.worker. The OAuth connections would block otherwise.
+                    final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
+                            Main.parent, apiUrl.toExternalForm(), Utils.newDirectExecutor());
+                    wizard.showDialog();
+                    OAuthAccessTokenHolder.getInstance().setSaveToPreferences(true);
+                    OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance());
+                    return wizard;
+                }
+            });
+            // exception handling differs from implementation at GuiHelper.runInEDTAndWait()
+            if (SwingUtilities.isEventDispatchThread()) {
+                authTask.run();
+            } else {
+                SwingUtilities.invokeAndWait(authTask);
+            }
+        } catch (MalformedURLException | InterruptedException | InvocationTargetException e) {
+            throw new MissingOAuthAccessTokenException();
+        }
+    }
+
     protected void addAuth(HttpClient connection) throws OsmTransferException {
-        String authMethod = Main.pref.get("osm-server.auth-method", "basic");
+        final String authMethod = OsmApi.getAuthMethod();
         if ("basic".equals(authMethod)) {
             addBasicAuthorizationHeader(connection);
Index: /trunk/src/org/openstreetmap/josm/tools/Utils.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 9351)
+++ /trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 9352)
@@ -49,6 +49,5 @@
 import java.util.Locale;
 import java.util.Objects;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.Executor;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.ForkJoinWorkerThread;
@@ -1431,4 +1430,17 @@
             }
         }, null, true);
+    }
+
+    /**
+     * Returns an executor which executes commands in the calling thread
+     * @return an executor
+     */
+    public static Executor newDirectExecutor() {
+        return new Executor() {
+            @Override
+            public void execute(Runnable command) {
+                command.run();
+            }
+        };
     }
 
