6

I have a Java native app I am trying to implement Oauth for. I have gone thru this article by Pat Patterson:

http://wiki.developerforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com

I am a little lost on a couple of points. I can work out how to make a call from Java to the initial URL (https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id=xxx&redirect_uri=myapp:oauth&display=full). From what I can see, this returns a redirect. What exactly does the Java app have to do to bring up the browser window with the authorization request?

Thx, Hamayoun

UPDATE:

Maybe I'm not explaining what I am looking for. Let me clarify. I want to get a refresh token for my desktop app, and store the refresh token. The article says:

In this flow, the client application directs (1) the user to a URL at the authorization server of the form: https://login.salesforce.com/services/oauth2/authorize?response_type=token& client_id=&redirect_uri=&display=touch&state=

On a browser, this redirects to a URL which takes the user to the SFDC login page, and then to a page asking the user to approve access to the application. So my first question is, in the Java app, how do I open the URL so that it redirects to the browser, while maintaining control of the browser? I tried JPaneEditor, it did not seem to work. The article then continues:

Now, rather than sending an authentication code to the client and it retrieving the access token via a POST request, a redirect is returned (3) containing several parameters in a URL fragment (i.e. after the hash '#' sign) - for example: myapp:oauth#access_token=00D50000000IZ3Z%21AQ0AQI6qUiQpGCAlNVAEOugF7J6Lr34LHSUUQZ_S4rnPzShAsJzG0qjW1XEx5R6kDORlWE2r9QXJpfAkAkq8V9k_V0PbXYjN&refresh_token=5Aep861eQO5D.6wJBuW5bbARbbxQ8hssCnY1dw3qi59jeys7ob.H_xM395_RJHukNjeustDru8BiA%3D%3D&instance_url=https%3A%2F%2Fna3.salesforce.com&id=https%3A%2F%2Flogin.salesforce.com%2Fid%2F00D50000000IZ3ZEAW%2F00550000001fg5OAAQ&issued_at=1298926970349&signature=Y5ici2QZsudYyH%2F4YWcJd1s3P89mLJPVsO0plVoHD4o%3D&state=mystate Since these parameters are passed in a fragment, they will remain on the client device, and will not be passed in an HTTP GET to the redirect URI. Note that the redirect URI may have a custom scheme, configured in the desktop/device OS to invoke a callback in the native app, for example, myapp:oauth, or it may have the https scheme. A native application can directly parse the incoming parameters from the fragment; in contrast a browser-based application would rely on JavaScript, served from the https redirect URI, which would have access to the fragment and its parameters.

So how exactly does my desktop app read the URL fragment at this point?

I hope this clarifies what I am looking for.

4 Answers 4

7
+25

If its a non Web Java desktop application, will it be used as a background process or will always have user access.

a. If its a background process, then you should simply store the credentials in property file may be encrypted and decrypt it before you hit the salesforce apis.. b. If its a user access process, then leverage swing based JDialogbox to ask user to enter cedentials or JEditorPane with no CSS , render html pages and compromise with the UI.

Hope that helps

Thanks Jatin

3
  • Jatin,first time it will be user access, after that I want to store refresh token and use it as background process. How exactly do I render the HTML Page? And then how do I get back the parameters passed to the callback URL?
    – hamayoun
    Oct 8, 2013 at 2:36
  • 1
    How about using a framework like Lobo : sourceforge.net/projects/xamj.. this might help in extending your java program to support web browser..give a shot..
    – Jatin Jain
    Oct 8, 2013 at 3:10
  • If you think I've answered your question, please vote on my answer and/or mark it as an accepted answer.
    – Jatin Jain
    Oct 9, 2013 at 18:28
2

I think this article by Jeff Douglas might help you out as well - he talks about how to setup a Connection Manager in JAVA to work with oAuth

1
  • That article seems to be directed to Java servlets, I am trying to do this for a desktop app.
    – hamayoun
    Oct 5, 2013 at 19:46
1

can you provide a bit more information?

Are you writing a native java mobile app? java desktop app?

if mobile, have you looked at the mobile sdk for android? (guessing on the android bit, but it's at least java)

1
  • Java desktop app
    – hamayoun
    Oct 5, 2013 at 19:44
1

The discussion here, about OAuth-ing to Twitter, should help : https://dev.twitter.com/discussions/13935

Basically, it says you needn't ask for a callback if you want a direct synchronous answer. Moreover, it gives very detailed instructions on how to pass the encoded parameters correctly, with extra libraries.

I hope this works for you, applied to your particular service.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .