Re: Simple user authorization for installed app: how to?

89 views
Skip to first unread message

Trung

unread,
Oct 11, 2012, 2:40:26 AM10/11/12
to google-a...@googlegroups.com
GData supports this feature.

I am not sure whether GData supports Python.

For Java:

1. Authorize
GoogleAuthTokenFactory factory = new GoogleAuthTokenFactory("ah, "MyCompany-MyApp-Version", null);
// Obtain authentication token from Google Account
String token = factory.getAuthToken(email, password, null, null, "ah", "MyCompany-MyApp-Version");
String loginUrl = "https://app-id.appspot.com/_ah/login?continue=/" + "&auth=" + token

URL url = new URL(loginUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();

int statusCode = connection.getResponseCode();
if ((statusCode != HttpURLConnection.HTTP_OK)
      && (statusCode != HttpURLConnection.HTTP_MOVED_TEMP)) {
   String responseText = Utils.getResposeText(connection);
   throw new StatusCodeException(statusCode, responseText);
}

// Retrieve the cookies
....


2. Access to http://app-id.appspot.com with cookies from step #1

Hope this help



On Wednesday, October 10, 2012 3:36:45 PM UTC+7, Ludd wrote:
Is there any simple user authorization mechanism for installed app in google app engine?

Background:
There is some functionality in my GAE app that only some group of user should have access to (for example, app admins). 
Utility to work with functionality implemented as python client application (runned on local pc, not in browser).

I've tried to use Users service, but users.get_current_user() returns None. AFAICS, it happens cause user login information stored as cookie in browser and admin utility communicates with GAE app using it's own httplib2 http object. And there is no information about user login in it.

Also I've tried to use oauth2, but Decorator implementation depends on users.get_current_user() and result is the same.

Seems that, "login: admin" field in app.yaml depends on Users service too.

Maybe there is some simple way to login user from client app without browser?

Ludd

unread,
Oct 12, 2012, 12:02:40 PM10/12/12
to google-a...@googlegroups.com
    There is python GDATA library. I've tried to to repeat same code on python but without any success. Neither I understand why it should work. Maybe I'm missing something?

client = GDClient(source = '...')
token = client.client_login(email = '...', password = '...', source = '...', service = 'apps', account_type='GOOGLE')

GDClient applies Authorization header to each http request, but Users service checks for cookie, not for auth header....

client.request('GET', 'http://127.0.0.1:8080/_ah/login?continue=/', auth_token = auth_token)

for localhost this request returns no cookies (no Set-Cookie in response headers). Why should it return anything - it's just logon screen...
for appspot.com - 500 Error: Server Error.
Reply all
Reply to author
Forward
0 new messages