1

I am trying to implement authentication of my standalone java application at VKontakte - Russian social network.

I want to avoid requesting a password from the user, so my method is like this:

  1. open default browser with a special generated URL
  2. in the opened page user clicks Accept button
  3. browser gets redirected to a special URL from where I can extract access_token which is supposed to be used for any other further request.

But the problem is that I do not know how to get that new URL from the browser. The code I am using is

if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                URI uri = new URI("some URL here");
                desktop.browse(uri);
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101

1 Answers1

1

You can't do that with Desktop.browse(). You are initializing an instance of a program(browser) that java has no access to. Java only passed the URL you provided.

(Theoretically it would be possible, if i.e. Desktop.browse() would start a custom made Browser that you can communicate with via Java API)

user1581900
  • 3,680
  • 4
  • 18
  • 21
  • any idea how to make this without Desktop.browse()? – Nikolay Kuznetsov Oct 10 '12 at 12:02
  • Do you need the user to click Accept in the browser? If it's a java applet you are developing how about you click it automatically? – user1581900 Oct 10 '12 at 12:03
  • Yes, without his click, redirect would not happen – Nikolay Kuznetsov Oct 10 '12 at 12:05
  • IF the Accept button has lots of JS behind it, you could use JUnit to simulate the browser. JUnit is used by software engineers to test their solutions, but I used it successfully to access websites with lots of JS. The browser won't be displayed and you could automate the clicking. From there you can obtain the redirect URL. – user1581900 Oct 10 '12 at 12:10
  • IF however the Accept button is simply another URL i suggest using URLConnection and finding its redirect value http://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url – user1581900 Oct 10 '12 at 12:11
  • If the user is not logged in, then he would need to input the password in the browser and clicking won't be automated. – Nikolay Kuznetsov Oct 10 '12 at 12:12
  • Can't you use the VKontakte API? Do they provide such a thing at all? – user1581900 Oct 10 '12 at 12:26
  • There are 3 options: 1) connect with email and pass: not recommended and outdated 2) webview in java application. Probably application can intercept email and password input by the user. 3) this approach – Nikolay Kuznetsov Oct 10 '12 at 12:28