Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryOAuthUI.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryOAuthUI.java	(revision 31387)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryOAuthUI.java	(revision 31388)
@@ -1,14 +1,13 @@
 package org.openstreetmap.josm.plugins.mapillary.gui;
 
-import java.util.Scanner;
+import java.awt.Desktop;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
-import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryOAuthApi;
-import org.scribe.builder.ServiceBuilder;
-import org.scribe.model.Token;
-import org.scribe.model.Verifier;
-import org.scribe.oauth.OAuthService;
+import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener;
 
 /**
@@ -20,25 +19,30 @@
 public class MapillaryOAuthUI extends JPanel {
 
-  private static final Token EMPTY_TOKEN = null;
+  PortListener portListener;
+  JLabel text;
 
+  /**
+   * Main constructor.
+   */
   public MapillaryOAuthUI() {
-    Scanner in = new Scanner(System.in);
-    OAuthService service = new ServiceBuilder()
-        .provider(MapillaryOAuthApi.class)
-        .apiKey("NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm")
-        .apiSecret("Secret").build();
-    String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
-    this.add(new JLabel("Login"));
-    System.out.println("Fetching the Authorization URL...");
-    System.out.println("Got the Authorization URL!");
-    System.out.println("Now go and authorize Scribe here:");
-    System.out.println(authorizationUrl);
-    System.out.println("And paste the authorization code here");
-    System.out.print(">>");
-    Verifier verifier = new Verifier(in.nextLine());
-    in.close();
-    System.out.println();
-    in.close();
+    text = new JLabel("Authorize in browser");
+    this.add(text);
+    portListener = new PortListener(text);
+    portListener.start();
+
+    String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=code&scope=user:email";
+    Desktop desktop = Desktop.getDesktop();
+    try {
+      desktop.browse(new URI(url));
+    } catch (IOException | URISyntaxException ex) {
+      ex.printStackTrace();
+    } catch (UnsupportedOperationException ex) {
+      Runtime runtime = Runtime.getRuntime();
+      try {
+        runtime.exec("xdg-open " + url);
+      } catch (IOException exc) {
+        exc.printStackTrace();
+      }
+    }
   }
-
 }
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/PortListener.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/PortListener.java	(revision 31388)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/PortListener.java	(revision 31388)
@@ -0,0 +1,78 @@
+package org.openstreetmap.josm.plugins.mapillary.oauth;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Scanner;
+
+import javax.swing.JLabel;
+import javax.swing.SwingUtilities;
+
+import org.openstreetmap.josm.Main;
+
+/**
+ * @author nokutu
+ *
+ */
+public class PortListener extends Thread {
+
+  JLabel text;
+
+  /**
+   * Main constructor.
+   *
+   * @param text
+   */
+  public PortListener(JLabel text) {
+    this.text = text;
+  }
+
+  @Override
+  public void run() {
+    try {
+      ServerSocket serverSocket = new ServerSocket(8763);
+      Socket clientSocket = serverSocket.accept();
+      PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
+      Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream()));
+      String s;
+      String code = null;
+      while (in.hasNextLine()) {
+        s = in.nextLine();
+        if (s.contains("?code=")) {
+          code = s.substring(s.indexOf("=") + 1, s.indexOf("HTTP") - 1);
+          break;
+        }
+      }
+
+      writeContent(out);
+
+      System.out.println("The code is: " + code);
+
+      out.close();
+      in.close();
+      serverSocket.close();
+    } catch (IOException e) {
+      Main.error(e);
+    }
+    if (!SwingUtilities.isEventDispatchThread()) {
+      SwingUtilities.invokeLater(new Runnable() {
+        @Override
+        public void run() {
+          text.setText("Authorization successful");
+        }
+      });
+    } else
+      text.setText("Authorization successful");
+  }
+
+  private void writeContent(PrintWriter out) {
+    String response = "";
+    response += "<html><body>Authorization successful</body></html>";
+    out.println("HTTP/1.1 200 OK");
+    out.println("Content-Length: " + response.length());
+    out.println("Content-Type: text/html" + "\r\n\r\n");
+    out.println(response);
+  }
+}
