当前位置: 首页>>代码示例>>Python>>正文


Python sessions.SecureCookieSessionInterface方法代码示例

本文整理汇总了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) 
开发者ID:fbsamples,项目名称:fbctf-2019-challenges,代码行数:6,代码来源:app.py

示例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 
开发者ID:fbsamples,项目名称:fbctf-2019-challenges,代码行数:12,代码来源:app.py

示例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 
开发者ID:noraj,项目名称:flask-session-cookie-manager,代码行数:15,代码来源:flask_session_cookie_manager2.py

示例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 
开发者ID:noraj,项目名称:flask-session-cookie-manager,代码行数:30,代码来源:flask_session_cookie_manager2.py

示例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 
开发者ID:noraj,项目名称:flask-session-cookie-manager,代码行数:15,代码来源:flask_session_cookie_manager3.py

示例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 
开发者ID:noraj,项目名称:flask-session-cookie-manager,代码行数:30,代码来源:flask_session_cookie_manager3.py

示例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) 
开发者ID:quay,项目名称:quay,代码行数:14,代码来源:signedgrant.py

示例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) 
开发者ID:quay,项目名称:quay,代码行数:35,代码来源:signedgrant.py

示例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) 
开发者ID:LyleMi,项目名称:Saker,代码行数:10,代码来源:flaskencoder.py


注:本文中的flask.sessions.SecureCookieSessionInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。