public
Fork of jchris/portable-google-app-engine-sdk
Description: A version of the Google App Engine SDK modified to work with AppDrop.com
Homepage: http://appdrop.com
Clone URL: git://github.com/sah/portable-google-app-engine-sdk.git
got the login loop working
jchris (author)
Sat Apr 12 17:44:29 -0700 2008
commit  8fc65b2bd0bc31ae2c20669ac4043c4d09f35015
tree    ad0f963a053ae1420f07841e106a675b38542a20
parent  66e93a3ace324490ec4749f9b64f9ba7b2c952bd
...
15
16
17
 
 
18
19
20
...
15
16
17
18
19
20
21
22
0
@@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0
 See the License for the specific language governing permissions and
0
 limitations under the License.
0
 
0
+Modifications for AppDrop.com deployment made by J. Chris Anderson (http://jchris.mfdz.com)
0
+
0
 
0
 DJANGO FRAMEWORK
0
 ================
...
274
275
276
277
 
 
278
279
280
...
286
287
288
 
289
290
291
...
301
302
303
304
 
305
306
307
...
319
320
321
 
 
 
 
 
 
 
 
 
322
323
324
...
479
480
481
482
 
483
484
485
...
274
275
276
 
277
278
279
280
281
...
287
288
289
290
291
292
293
...
303
304
305
 
306
307
308
309
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
490
491
492
 
493
494
495
496
0
@@ -274,7 +274,8 @@ class MatcherDispatcher(URLDispatcher):
0
                login_url,
0
                url_matchers,
0
                get_user_info=dev_appserver_login.GetUserInfo,
0
- login_redirect=dev_appserver_login.LoginRedirect):
0
+ login_redirect=dev_appserver_login.LoginRedirect,
0
+ clear_cookies=dev_appserver_login.ClearUserInfoCookie):
0
     """Initializer.
0
 
0
     Args:
0
@@ -286,6 +287,7 @@ class MatcherDispatcher(URLDispatcher):
0
     self._url_matchers = tuple(url_matchers)
0
     self._get_user_info = get_user_info
0
     self._login_redirect = login_redirect
0
+ self._clear_cookies = clear_cookies
0
 
0
   def Dispatch(self,
0
                relative_url,
0
@@ -301,7 +303,7 @@ class MatcherDispatcher(URLDispatcher):
0
     path variable supplied to this method is ignored.
0
     """
0
     cookies = ', '.join(headers.getheaders('cookie'))
0
- email, nickname, admin = self._get_user_info(cookies)
0
+ email, nickname, admin, valid_cookie = self._get_user_info(cookies)
0
 
0
     for matcher in self._url_matchers:
0
       dispatcher, matched_path, requires_login, admin_only = matcher.Match(relative_url)
0
@@ -319,6 +321,15 @@ class MatcherDispatcher(URLDispatcher):
0
           base_env_dict['SERVER_PORT'],
0
           relative_url,
0
           outfile)
0
+ elif not valid_cookie:
0
+ output_headers = []
0
+ output_headers.append(self._clear_cookies())
0
+ outfile.write('Status: 302 Redirecting to continue URL\r\n')
0
+ for header in output_headers:
0
+ outfile.write(header)
0
+ outfile.write('Location: %s\r\n' % relative_url)
0
+ outfile.write('\r\n')
0
+
0
       elif admin_only and not admin:
0
         outfile.write('Status: %d Not authorized\r\n'
0
                       '\r\n'
0
@@ -479,7 +490,7 @@ def SetupEnvironment(cgi_path,
0
   env['CONTENT_LENGTH'] = headers.getheader('content-length', '')
0
 
0
   cookies = ', '.join(headers.getheaders('cookie'))
0
- email, nickname, admin = get_user_info(cookies)
0
+ email, nickname, admin, valid_cookie = get_user_info(cookies)
0
   env['USER_EMAIL'] = email
0
 
0
   if admin:
...
69
70
71
 
72
73
74
...
81
82
83
 
84
85
86
87
 
88
89
90
...
164
165
166
167
168
 
 
 
 
169
170
171
...
182
183
184
185
 
186
187
188
189
 
190
191
192
 
193
194
195
...
205
206
207
208
 
 
 
 
 
 
 
209
210
211
...
220
221
222
223
 
224
225
 
226
227
228
...
69
70
71
72
73
74
75
...
82
83
84
85
86
87
88
 
89
90
91
92
...
166
167
168
 
 
169
170
171
172
173
174
175
...
186
187
188
 
189
190
191
192
 
193
194
195
 
196
197
198
199
...
209
210
211
 
212
213
214
215
216
217
218
219
220
221
...
230
231
232
 
233
234
 
235
236
237
238
0
@@ -69,6 +69,7 @@ def GetUserInfo(http_cookie, cookie_name=COOKIE_NAME):
0
   cookie = Cookie.SimpleCookie(http_cookie)
0
 
0
   cookie_value = ''
0
+ valid_cookie = True
0
   if cookie_name in cookie:
0
     cookie_value = cookie[cookie_name].value
0
 
0
@@ -81,10 +82,11 @@ def GetUserInfo(http_cookie, cookie_name=COOKIE_NAME):
0
     vhsh = sha.new(email+nickname+admin+COOKIE_SECRET).hexdigest()
0
     if hsh != vhsh:
0
       logging.info(email+" had invalid cookie")
0
+ valid_cookie = False
0
       # todo clear the cookie
0
       # redirect to os.environ['PATH_INFO'] with the cookier clearing?
0
     
0
- return email, nickname, (admin == 'True')
0
+ return email, nickname, (admin == 'True'), valid_cookie
0
 
0
 
0
 def CreateCookieData(email, nickname, admin):
0
@@ -164,8 +166,10 @@ def LoginRedirect(login_url,
0
   outfile.write('Status: 302 Requires login\r\n')
0
   outfile.write('Location: %s\r\n\r\n' % redirect_url)
0
 
0
-def LoginServiceRedirect(dest_url, endpoint, outfile):
0
- redirect_url = '%s?%s=%s' % (endpoint, CONTINUE_PARAM, urllib.quote(dest_url))
0
+def LoginServiceRedirect(dest_url, endpoint, ah_url, outfile):
0
+ redirect_url = '%s?%s=%s' % (endpoint,
0
+ CONTINUE_PARAM,
0
+ urllib.quote('%s?%s=%s' %(ah_url,CONTINUE_PARAM,dest_url)))
0
                                            
0
   outfile.write('Status: 302 Redirecting to login service URL\r\n')
0
   outfile.write('Location: %s\r\n' % redirect_url)
0
@@ -182,14 +186,14 @@ def Logout(continue_url, outfile):
0
   outfile.write('\r\n')
0
   
0
   
0
-def LoginFromAuth(token, continue_url, auth_endpoint, outfile):
0
+def LoginFromAuth(token, continue_url, auth_endpoint, host, outfile):
0
   """Uses the auth token to fetch the userdata from appdrop, then sets the cookie"""
0
   output_headers = []
0
   
0
- auth_url = "%s?token=%s" % (auth_endpoint,token)
0
+ auth_url = "%s?token=%s&app=%s" % (auth_endpoint,token,host)
0
   logging.info('fetching: '+auth_url)
0
   result = urlfetch.fetch(auth_url);
0
-
0
+ logging.info('result: '+result.content)
0
   if (result.status_code == 200):
0
     userinfo = simplejson.loads(result.content)
0
     output_headers.append(SetUserInfoCookie(userinfo['email'], userinfo['nickname'], userinfo['admin']))
0
@@ -205,7 +209,13 @@ def LoginFromAuth(token, continue_url, auth_endpoint, outfile):
0
 def main():
0
   """Runs the login and logout CGI redirector script."""
0
   form = cgi.FieldStorage()
0
- login_url = os.environ['PATH_INFO']
0
+ ah_path = os.environ['PATH_INFO']
0
+ host = 'http://'+os.environ['SERVER_NAME']
0
+ if os.environ['SERVER_PORT'] != '80':
0
+ host = host + ":" + os.environ['SERVER_PORT']
0
+
0
+ ah_login_url = host+ah_path
0
+
0
   action = form.getfirst(ACTION_PARAM)
0
 
0
   if action == None:
0
@@ -220,9 +230,9 @@ def main():
0
   if action.lower() == LOGOUT_ACTION.lower():
0
     Logout(continue_url, sys.stdout)
0
   elif auth_token == '':
0
- LoginServiceRedirect(continue_url, login_service_endpoint, sys.stdout)
0
+ LoginServiceRedirect(continue_url, login_service_endpoint, ah_login_url, sys.stdout)
0
   else:
0
- LoginFromAuth(auth_token, continue_url, auth_endpoint, sys.stdout)
0
+ LoginFromAuth(auth_token, continue_url, auth_endpoint, host, sys.stdout)
0
 
0
   return 0
0
 
...
160
161
162
 
163
164
165
...
194
195
196
 
 
 
197
198
199
...
160
161
162
163
164
165
166
...
195
196
197
198
199
200
201
202
203
0
@@ -160,6 +160,7 @@ def ParseArguments(argv):
0
         'enable_sendmail',
0
         'help',
0
         'history_path=',
0
+ 'login_url=',
0
         'port=',
0
         'require_indexes',
0
         'smtp_host=',
0
@@ -194,6 +195,9 @@ def ParseArguments(argv):
0
     if option == '--datastore_path':
0
       option_dict[ARG_DATASTORE_PATH] = value
0
 
0
+ if option == '--login_url':
0
+ option_dict[ARG_LOGIN_URL] = value
0
+
0
     if option == '--history_path':
0
       option_dict[ARG_HISTORY_PATH] = value
0
 

Comments

    No one has commented yet.