當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。