我正在尝试为 AuthKit 实现我自己的身份验证方法,并试图弄清楚一些内置方法是如何工作的。特别是,我试图弄清楚如何正确更新REMOTE_USER
for environ
。
这就是它在内部的处理方式,authkit.authenticate.basic
但它非常令人困惑。我找不到任何定义REMOTE_USER
和AUTH_TYPE
定义的地方。这里有什么奇怪的事情吗?如果有,那是什么?
def __call__(self, environ, start_response):
environ['authkit.users'] = self.users
result = self.authenticate(environ)
if isinstance(result, str):
AUTH_TYPE.update(environ, 'basic')
REMOTE_USER.update(environ, result)
return self.application(environ, start_response)
实际上有许多像这样的大写字母我找不到定义。例如,AUTHORIZATION
从下面哪里来:
def authenticate(self, environ):
authorization = AUTHORIZATION(environ)
if not authorization:
return self.build_authentication()
(authmeth, auth) = authorization.split(' ',1)
if 'basic' != authmeth.lower():
return self.build_authentication()
auth = auth.strip().decode('base64')
username, password = auth.split(':',1)
if self.authfunc(environ, username, password):
return username
return self.build_authentication()
我觉得我可能遗漏了一些对environ
dict 的特殊语法处理,但这里可能还有其他一些非常奇怪的事情,对于像我这样刚接触 Python 的人来说并不是很明显。