cancel
Showing results for 
Search instead for 
Did you mean: 

Cloud API, Oauth tokens

vsams14
Champ in-the-making
Champ in-the-making
Hello,
I am new to alfresco, and to oauth authentication in general. I'm working with another person who wants to make use of alfresco in the cloud, and have been asked to program the client. I've had issues with Jeff Potts's alfresco api java examples on google code throwing random errors that don't make much sense to me. I don't expect code handouts, but some pointers and hints would be very helpful to get me started. "What oauth library should I use, and how do incorporate it into my code" is probably the biggest question that I have, and any help would be much appreciated. I understand cmis, so I'm sure that once I am able to successfully connect to the cloud repository through the client, everything else should be smooth sailing.
Again, thank you very much,
Val Samsonov
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator
It would help me improve those API examples if you'd let me know specifically what errors you are seeing.

The choice of OAuth client is totally up you to, but if the examples that use the Google OAuth2 library aren't working for you, you might take a look at Jared Ottley's Spring Social plug-in:

https://github.com/Alfresco/spring-social-alfresco

And you might also take a look at Gethin James' example here:
https://github.com/Alfresco/alfresco-oauth-sample

Jeff

vsams14
Champ in-the-making
Champ in-the-making
Well, there are definitely less errors now than before the update. Thanks for that by the way. Maven works great now and all code references seem to work.
When I run "GetSitesExample", I get this as the output:
<java>
java.net.ConnectException: Connection refused: connect
Done!
   at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
   at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
   at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
   at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
   at java.net.PlainSocketImpl.connect(Unknown Source)
   at java.net.SocksSocketImpl.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at sun.net.NetworkClient.doConnect(Unknown Source)
   at sun.net.www.http.HttpClient.openServer(Unknown Source)
   at sun.net.www.http.HttpClient.openServer(Unknown Source)
   at sun.net.www.http.HttpClient.<init>(Unknown Source)
   at sun.net.www.http.HttpClient.New(Unknown Source)
   at sun.net.www.http.HttpClient.New(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
   at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93)
   at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:964)
   at com.alfresco.api.example.BasePublicAPIExample.getHomeNetwork(BasePublicAPIExample.java:82)
   at com.alfresco.api.example.GetSitesExample.doExample(GetSitesExample.java:27)
   at com.alfresco.api.example.GetSitesExample.main(GetSitesExample.java:21)
</java>

Like I said, I hadn't done any work with oauth before this, and I honestly didn't even realise that there was a library being used to implement it. I guess with your example code pulling a very large number of libraries, it was hard to tell which one was relevant and being used for this function, if any. I'll look into google's library and hopefully get it to connect.
Val

jpotts
World-Class Innovator
World-Class Innovator
…make sure that you:

(1) Have registered for an API key at http://www.alfresco.com/develop and you've obtained your secret and your API key and have placed them in config.properties.

(2) When your browser launches so that Alfresco can ask you to grant access to your account, make sure you are logging in using your Alfresco in the cloud account. The username and password for that account are completely different credentials than what you use to log in to the Alfresco developer portal.

Another thing to try is when the code runs, you should be seeing an access token in the System console. You can grab that and then use an HTTP client to hit the same URL the code is hitting. Just add the access token in the Authorization header, like this:
Authorization: Bearer 00000000-0000-0000-0000-000000000000

Where that string of zero's is the access token you copied from the system console.

If you aren't getting as far as seeing the access token, then I suspect you aren't entering the api key or secret correctly or your callback URL doesn't match up.

Jeff

vsams14
Champ in-the-making
Champ in-the-making
…but I have made sure that the api key and secret, as well as the callback url are all set correctly. The browser does not open. No token comes up in the console. What could be causing this?
Val