2012-02-27 129 views
0

所以我正在使用AppEngine(Python),我想要做的就是提供OpenID登录设置一个默认提供程序,以便用户无需使用该提供程序即可登录。事情是,我想在登录后立即提示用户输入密码以显示静态内容(HTML页面);如果用户没有输入正确的密码,那么我想将它们重定向到另一个页面。保护必须是服务器端请:)任何想法??密码保护静态页面AppEngine HowTo?

P.S.我正在寻求类似于“.htaccess/htpasswd”的解决方案,但对于应用程序引擎。

+0

app.yaml中使用“权限设置”不要么是因为一个选项我想手动将密码发送给已注册/可登录的用户,或者我可以为每个人选择密码也会很酷;但无论如何...基本思路是用一个预先定义的密码保护页面,并将其发送给用户 – Jmlevick 2012-02-27 06:54:02

回答

2

AFAIK,GAE不支持这种设置(OpenID登录后的静态密码)。

我看到,使这项工作将通过您的处理程序提供静态内容的唯一方法:

  1. 客户机对静态内容
  2. 你的处理程序注册处理这个URL请求
  3. 处理程序检查是用户身份验证。如果没有,请求密码。
  4. 经过身份验证后,处理程序将读取静态文件并将其发回给用户。
0

尝试了这一点,你可以模仿的.htaccess样式密码与谷歌应用程序引擎:

def basicAuth(func): 
    def callf(webappRequest, *args, **kwargs): 
    # Parse the header to extract a user/password combo. 
    # We're expecting something like "Basic XZxgZRTpbjpvcGVuIHYlc4FkZQ==" 
    auth_header = webappRequest.request.headers.get('Authorization') 

    if auth_header == None: 
     webappRequest.response.set_status(401, message="Authorization Required") 
     webappRequest.response.headers['WWW-Authenticate'] = 'Basic realm="Kalydo School"' 
    else: 
     # Isolate the encoded user/passwd and decode it 
     auth_parts = auth_header.split(' ') 
     user_pass_parts = base64.b64decode(auth_parts[1]).split(':') 
     user_arg = user_pass_parts[0] 
     pass_arg = user_pass_parts[1] 

     if user_arg != "admin" or pass_arg != "foobar": 
     webappRequest.response.set_status(401, message="Authorization Required") 
     webappRequest.response.headers['WWW-Authenticate'] = 'Basic realm="Secure Area"' 
     # Rendering a 401 Error page is a good way to go... 
     self.response.out.write(template.render('templates/error/401.html', {})) 
     else: 
     return func(webappRequest, *args, **kwargs) 

    return callf 

class AuthTest(webapp.RequestHandler): 
    @basicAuth 
    def get(self): 
    .... 

How-To: Dynamic WWW-Authentication (.htaccess style) on Google App Engine

+0

嘿,这是一个很好的解决方案。考虑使用auth_header是None而不是auth_header == None。 – 2018-03-10 23:11:56