本文整理汇总了Python中flask.sessions.SecureCookieSessionInterface方法的典型用法代码示例。如果您正苦于以下问题:Python sessions.SecureCookieSessionInterface方法的具体用法?Python sessions.SecureCookieSessionInterface怎么用?Python sessions.SecureCookieSessionInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.sessions
的用法示例。
在下文中一共展示了sessions.SecureCookieSessionInterface方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unsign
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def unsign(val):
scsi = SecureCookieSessionInterface()
ser = scsi.get_signing_serializer(app)
return ser.loads(val)
示例2: sign
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def sign(val):
scsi = SecureCookieSessionInterface()
ser = scsi.get_signing_serializer(app)
return ser.dumps(val)
# END COOKIE UTILS
# MODEL
示例3: encode
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def encode(cls, secret_key, session_cookie_structure):
""" Encode a Flask session cookie """
try:
app = MockApp(secret_key)
session_cookie_structure = dict(ast.literal_eval(session_cookie_structure))
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.dumps(session_cookie_structure)
except Exception as e:
return "[Encoding error] {}".format(e)
raise e
示例4: decode
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def decode(cls, session_cookie_value, secret_key=None):
""" Decode a Flask cookie """
try:
if(secret_key==None):
compressed = False
payload = session_cookie_value
if payload.startswith('.'):
compressed = True
payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data)
if compressed:
data = zlib.decompress(data)
return data
else:
app = MockApp(secret_key)
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.loads(session_cookie_value)
except Exception as e:
return "[Decoding error] {}".format(e)
raise e
示例5: encode
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def encode(secret_key, session_cookie_structure):
""" Encode a Flask session cookie """
try:
app = MockApp(secret_key)
session_cookie_structure = dict(ast.literal_eval(session_cookie_structure))
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.dumps(session_cookie_structure)
except Exception as e:
return "[Encoding error] {}".format(e)
raise e
示例6: decode
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def decode(session_cookie_value, secret_key=None):
""" Decode a Flask cookie """
try:
if(secret_key==None):
compressed = False
payload = session_cookie_value
if payload.startswith('.'):
compressed = True
payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data)
if compressed:
data = zlib.decompress(data)
return data
else:
app = MockApp(secret_key)
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.loads(session_cookie_value)
except Exception as e:
return "[Decoding error] {}".format(e)
raise e
示例7: generate_signed_token
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def generate_signed_token(grants, user_context):
"""
Generates a signed session token with the given grants and user context.
"""
ser = SecureCookieSessionInterface().get_signing_serializer(app)
data_to_sign = {
"grants": grants,
"user_context": user_context,
}
encrypted = ser.dumps(data_to_sign)
return "{0}{1}".format(SIGNATURE_PREFIX, encrypted)
示例8: validate_signed_grant
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def validate_signed_grant(auth_header):
"""
Validates a signed grant as found inside an auth header and returns whether it points to a valid
grant.
"""
if not auth_header:
return ValidateResult(AuthKind.signed_grant, missing=True)
# Try to parse the token from the header.
normalized = [part.strip() for part in auth_header.split(" ") if part]
if normalized[0].lower() != "token" or len(normalized) != 2:
logger.debug("Not a token: %s", auth_header)
return ValidateResult(AuthKind.signed_grant, missing=True)
# Check that it starts with the expected prefix.
if not normalized[1].startswith(SIGNATURE_PREFIX):
logger.debug("Not a signed grant token: %s", auth_header)
return ValidateResult(AuthKind.signed_grant, missing=True)
# Decrypt the grant.
encrypted = normalized[1][len(SIGNATURE_PREFIX) :]
ser = SecureCookieSessionInterface().get_signing_serializer(app)
try:
token_data = ser.loads(encrypted, max_age=app.config["SIGNED_GRANT_EXPIRATION_SEC"])
except BadSignature:
logger.warning("Signed grant could not be validated: %s", encrypted)
return ValidateResult(
AuthKind.signed_grant, error_message="Signed grant could not be validated"
)
logger.debug("Successfully validated signed grant with data: %s", token_data)
return ValidateResult(AuthKind.signed_grant, signed_data=token_data)
示例9: __init__
# 需要导入模块: from flask import sessions [as 别名]
# 或者: from flask.sessions import SecureCookieSessionInterface [as 别名]
def __init__(self, secret_key=None):
self.compressed = False
if secret_key is None:
self.session_serializer = None
else:
app = Flask(__name__)
app.secret_key = secret_key
self.session_serializer = SecureCookieSessionInterface().get_signing_serializer(app)