Ignore:
Timestamp:
2015-07-16T13:56:16+02:00 (9 years ago)
Author:
nokutu
Message:

Started login system, code is already gathered, only the last POST to get the access token left.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryOAuthUI.java

    r31355 r31388  
    11package org.openstreetmap.josm.plugins.mapillary.gui;
    22
    3 import java.util.Scanner;
     3import java.awt.Desktop;
     4import java.io.IOException;
     5import java.net.URI;
     6import java.net.URISyntaxException;
    47
    58import javax.swing.JLabel;
    69import javax.swing.JPanel;
    710
    8 import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryOAuthApi;
    9 import org.scribe.builder.ServiceBuilder;
    10 import org.scribe.model.Token;
    11 import org.scribe.model.Verifier;
    12 import org.scribe.oauth.OAuthService;
     11import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener;
    1312
    1413/**
     
    2019public class MapillaryOAuthUI extends JPanel {
    2120
    22   private static final Token EMPTY_TOKEN = null;
     21  PortListener portListener;
     22  JLabel text;
    2323
     24  /**
     25   * Main constructor.
     26   */
    2427  public MapillaryOAuthUI() {
    25     Scanner in = new Scanner(System.in);
    26     OAuthService service = new ServiceBuilder()
    27         .provider(MapillaryOAuthApi.class)
    28         .apiKey("NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm")
    29         .apiSecret("Secret").build();
    30     String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
    31     this.add(new JLabel("Login"));
    32     System.out.println("Fetching the Authorization URL...");
    33     System.out.println("Got the Authorization URL!");
    34     System.out.println("Now go and authorize Scribe here:");
    35     System.out.println(authorizationUrl);
    36     System.out.println("And paste the authorization code here");
    37     System.out.print(">>");
    38     Verifier verifier = new Verifier(in.nextLine());
    39     in.close();
    40     System.out.println();
    41     in.close();
     28    text = new JLabel("Authorize in browser");
     29    this.add(text);
     30    portListener = new PortListener(text);
     31    portListener.start();
     32
     33    String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=code&scope=user:email";
     34    Desktop desktop = Desktop.getDesktop();
     35    try {
     36      desktop.browse(new URI(url));
     37    } catch (IOException | URISyntaxException ex) {
     38      ex.printStackTrace();
     39    } catch (UnsupportedOperationException ex) {
     40      Runtime runtime = Runtime.getRuntime();
     41      try {
     42        runtime.exec("xdg-open " + url);
     43      } catch (IOException exc) {
     44        exc.printStackTrace();
     45      }
     46    }
    4247  }
    43 
    4448}
Note: See TracChangeset for help on using the changeset viewer.