本文整理匯總了Python中werkzeug.datastructures.WWWAuthenticate.stale方法的典型用法代碼示例。如果您正苦於以下問題:Python WWWAuthenticate.stale方法的具體用法?Python WWWAuthenticate.stale怎麽用?Python WWWAuthenticate.stale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.datastructures.WWWAuthenticate
的用法示例。
在下文中一共展示了WWWAuthenticate.stale方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: digest_challenge_response
# 需要導入模塊: from werkzeug.datastructures import WWWAuthenticate [as 別名]
# 或者: from werkzeug.datastructures.WWWAuthenticate import stale [as 別名]
def digest_challenge_response(app, qop, algorithm, stale = False):
response = app.make_response('')
response.status_code = 401
# RFC2616 Section4.2: HTTP headers are ASCII. That means
# request.remote_addr was originally ASCII, so I should be able to
# encode it back to ascii. Also, RFC2617 says about nonces: "The
# contents of the nonce are implementation dependent"
nonce = H(b''.join([
getattr(request, 'remote_addr', u'').encode('ascii'),
b':',
str(time.time()).encode('ascii'),
b':',
os.urandom(10)
]), algorithm)
opaque = H(os.urandom(10), algorithm)
auth = WWWAuthenticate("digest")
auth.set_digest('[email protected]', nonce, opaque=opaque,
qop=('auth', 'auth-int') if qop is None else (qop,), algorithm=algorithm)
auth.stale = stale
response.headers['WWW-Authenticate'] = auth.to_header()
return response