views:

65

answers:

1

I get the following error from following piece of code. I am trying to login to Google sites service through GAE apps.

"The page you requested is invalid. "

    String authenticationUrl = userService.isUserLoggedIn()
    ? userService.createLogoutURL(MainServlet.MAIN_URL)
    : userService.createLoginURL(MainServlet.MAIN_URL+"?close=1");
    googleData.setAuthenticationUrl(authenticationUrl);

The complete url for login

https://www.google.com/a/example.com/ServiceLogin?service=ah&passive=true&continue=http%3A//myapp.appspot.com/%5Fah/login?continue=http%3A//myapp.appspot.com/main%3Fclose%3D1&ltmpl=ga&ahname=Myapp+Google+Sites&sig=7cbc9f7c9e6ca443ed49f7ce9465e775

A: 

I think that you may have misunderstood the use and purpose of createLoginURL. This method is intended to provide a URL that allows someone to log in to your application and your application alone. It does not provide a means to log in to other Google services such as Sites.

It is possible to have your application log on to and access Sites or any other secured web application, but Google AppEngine does not provide a canned means of doing so. You will need to write the code to do it yourself.

Generally, what will happen is that you will request a URL and the response will have an HTTP status code of 302 with the URL of the login page located in the Location header field. You would then send a request to that page which should come back with a 200 response and somewhere inside the body of the response would be a username and password field that you would need to provide and POST back. If the credentials were valid, the server might then return an authentication cookie which you would pass on each subsequent request.

If you are versed at all in Python, you can see an example of how this works in some code from my AppEngine MVC framework project. Look at this file: http://code.google.com/p/gae-mvc-engine/source/browse/trunk/MVCTests.py and check out the ActiontestCase.run_action method. It handles making a request to an AppEngine application that requires authentication. It is not yet terribly-well commented -- and for that I aplogize -- but I hope that it will provide a useful example. If, indeed, I have understood the nature of your problem correctly.

Adam Crossland