I'm trying to access an OAuth-protected resource on Google App Engine using a Java/Groovy client. However the authentication is not working and my GET requests are just bringing back the Google Accounts login page HTML.
I get the same results with HTTPBuilder/signpost and with google-oauth-java-client.
Here's what I've done:
- Set up an OAuth provider as described in http://ikaisays.com/2011/05/26/setting-up-an-oauth-provider-on-google-app-engine/
- Created a 'hello world' servlet (actually a Gaelyk groovlet) mapped to
http://<my-app>.appspot.com/rest/hello
- Deployed the servlet to gae and confirmed I can GET via a browser.
Added a security constraint to my web.xml and redeployed.
<security-constraint> <web-resource-collection> <web-resource-name>Rest</web-resource-name> <url-pattern>/rest/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> </security-constraint>
Confirmed that a browser GET requires a Google Accounts login and that after login I can access the servlet.
- Did the 3-legged OAuth dance as described in http://groovy.codehaus.org/modules/http-builder/doc/auth.html to get the access and client secret tokens.
Use the tokens in a RESTClient as follows (following instructions in the link above)
def client = new RESTClient('http://<my-app>.appspot.com' ) def consumerKey = <my consumer key> def consumerSecret = <my consumer secret> def accessToken = <my access token> def secretToken = <my secret token> client.auth.oauth consumerKey, consumerSecret, accessToken, secretToken def resp = client.get(path:'/rest/hello') assert resp.data == 'Hello world'
The assert fails since the response is the Google Accounts login page.
- I get the same behaviour when using google-oauth-java-client.
I've been through the process above several times, checking for copy/paste errors in the tokens and ensuring that I'm not getting the tokens mixed up.
This is with Groovy 1.8.2, OSX Java 1.6.0_29, HTTPBuilder 0.5.1, gaelyk 1.1.
Any ideas? Thanks.