Changeset 31388 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-07-16T13:56:16+02:00 (9 years ago)
- 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 1 1 package org.openstreetmap.josm.plugins.mapillary.gui; 2 2 3 import java.util.Scanner; 3 import java.awt.Desktop; 4 import java.io.IOException; 5 import java.net.URI; 6 import java.net.URISyntaxException; 4 7 5 8 import javax.swing.JLabel; 6 9 import javax.swing.JPanel; 7 10 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; 11 import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener; 13 12 14 13 /** … … 20 19 public class MapillaryOAuthUI extends JPanel { 21 20 22 private static final Token EMPTY_TOKEN = null; 21 PortListener portListener; 22 JLabel text; 23 23 24 /** 25 * Main constructor. 26 */ 24 27 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 } 42 47 } 43 44 48 }
Note:
See TracChangeset
for help on using the changeset viewer.