當前位置: 首頁>>代碼示例>>Python>>正文


Python itsdangerous.URLSafeTimedSerializer方法代碼示例

本文整理匯總了Python中itsdangerous.URLSafeTimedSerializer方法的典型用法代碼示例。如果您正苦於以下問題:Python itsdangerous.URLSafeTimedSerializer方法的具體用法?Python itsdangerous.URLSafeTimedSerializer怎麽用?Python itsdangerous.URLSafeTimedSerializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在itsdangerous的用法示例。


在下文中一共展示了itsdangerous.URLSafeTimedSerializer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_session

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_session(response):
    """ Return session cookie contents.
    This a base64 encoded json.
    Returns a dict
    """

    # Alas seems like if there are multiple set-cookie headers - we are on our own
    for index, h in enumerate(response.headers):
        if h[0] == "Set-Cookie":
            cookie = parse_cookie(response.headers[index][1])
            encoded_cookie = cookie.get("session", None)
            if encoded_cookie:
                serializer = URLSafeTimedSerializer(
                    "secret", serializer=TaggedJSONSerializer()
                )
                val = serializer.loads_unsafe(encoded_cookie)
                return val[1] 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:19,代碼來源:test_utils.py

示例2: get_serializer

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_serializer(secret: str, legacy: bool, salt: str) -> URLSafeTimedSerializer:
    """
    Get a (cached) serializer instance
    :param secret: Secret key
    :param salt: Salt
    :param legacy: Should the legacy timestamp generator be used?
    :return: Flask session serializer
    """
    if legacy:
        signer = LegacyTimestampSigner
    else:
        signer = TimestampSigner

    return URLSafeTimedSerializer(
        secret_key=secret,
        salt=salt,
        serializer=TaggedJSONSerializer(),
        signer=signer,
        signer_kwargs={
            'key_derivation': 'hmac',
            'digest_method': hashlib.sha1}) 
開發者ID:Paradoxis,項目名稱:Flask-Unsign,代碼行數:23,代碼來源:session.py

示例3: send_password_reset_email

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def send_password_reset_email(user_email):
    password_reset_serializer = URLSafeTimedSerializer(app.config['SECRET_KEY'])

    password_reset_url = url_for(
        'users.reset_with_token',
        token=password_reset_serializer.dumps(user_email, salt='password-reset-salt'),
        _external=True)

    html = render_template(
        'email_password_reset.html',
        password_reset_url=password_reset_url)

    send_email('Password Reset Requested', [user_email], html)


# ROUTES 
開發者ID:jelmerdejong,項目名稱:flask-app-blueprint,代碼行數:18,代碼來源:views.py

示例4: get_signing_serializer

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_signing_serializer(self, app: "Quart") -> Optional[URLSafeTimedSerializer]:
        """Return a serializer for the session that also signs data.

        This will return None if the app is not configured for secrets.
        """
        if not app.secret_key:
            return None

        options = {"key_derivation": self.key_derivation, "digest_method": self.digest_method}
        return URLSafeTimedSerializer(
            app.secret_key, salt=self.salt, serializer=self.serializer, signer_kwargs=options
        ) 
開發者ID:pgjones,項目名稱:quart,代碼行數:14,代碼來源:sessions.py

示例5: get_signing_serializer

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_signing_serializer(self, app):
        if not app.secret_key:
            return None
        signer_kwargs = dict(
            key_derivation=self.key_derivation,
            digest_method=self.digest_method
        )
        return URLSafeTimedSerializer(app.secret_key, salt=self.salt,
                                      serializer=self.serializer,
                                      signer_kwargs=signer_kwargs) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:sessions.py

示例6: get_serializer

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_serializer():
    global serializer
    if serializer is None:
        serializer = URLSafeTimedSerializer(settings.load()['database']['crypto']['key'])
    return serializer 
開發者ID:mitre,項目名稱:cascade-server,代碼行數:7,代碼來源:users.py

示例7: generate_confirmation_token

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def generate_confirmation_token(config, email):
    """generate confirmation token using user's email via itsdangerous"""
    serializer = URLSafeTimedSerializer(config['SECRET_KEY'])
    return serializer.dumps(email, salt=config['EMAIL']['salt']) 
開發者ID:DoubleCiti,項目名稱:daimaduan.com,代碼行數:6,代碼來源:email_confirmation.py

示例8: validate_token

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def validate_token(config, token, expire_time=3600):
    """from token and expire_time to confirm user's email"""
    serializer = URLSafeTimedSerializer(config['SECRET_KEY'])
    try:
        confirmed_email = serializer.loads(token, max_age=expire_time, salt=config['EMAIL']['salt'])
    except Exception:
        return False
    return confirmed_email 
開發者ID:DoubleCiti,項目名稱:daimaduan.com,代碼行數:10,代碼來源:email_confirmation.py

示例9: _get_serializer

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def _get_serializer(app, name):
    secret_key = app.config.get("SECRET_KEY")
    salt = app.config.get("SECURITY_%s_SALT" % name.upper())
    return URLSafeTimedSerializer(secret_key=secret_key, salt=salt) 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:6,代碼來源:core.py

示例10: generate_csrf

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def generate_csrf(secret_key=None, token_key=None):
    """Generate a CSRF token. The token is cached for a request, so multiple
    calls to this function will generate the same token.

    During testing, it might be useful to access the signed token in
    ``g.csrf_token`` and the raw token in ``session['csrf_token']``.

    :param secret_key: Used to securely sign the token. Default is
        ``WTF_CSRF_SECRET_KEY`` or ``SECRET_KEY``.
    :param token_key: Key where token is stored in session for comparision.
        Default is ``WTF_CSRF_FIELD_NAME`` or ``'csrf_token'``.
    """

    secret_key = _get_config(
        secret_key, 'WTF_CSRF_SECRET_KEY', current_app.secret_key,
        message='A secret key is required to use CSRF.'
    )
    field_name = _get_config(
        token_key, 'WTF_CSRF_FIELD_NAME', 'csrf_token',
        message='A field name is required to use CSRF.'
    )

    if field_name not in g:
        if field_name not in session:
            session[field_name] = hashlib.sha1(os.urandom(64)).hexdigest()

        s = URLSafeTimedSerializer(secret_key, salt='wtf-csrf-token')
        setattr(g, field_name, s.dumps(session[field_name]))

    return g.get(field_name) 
開發者ID:liantian-cn,項目名稱:RSSNewsGAE,代碼行數:32,代碼來源:csrf.py

示例11: create_unique_url

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def create_unique_url(payload, salt=None):
    config = SiteConfiguration.get_solo()
    salt = config.salt if salt is None else salt
    s = URLSafeTimedSerializer(settings.SECRET_KEY, salt=salt)
    token = s.dumps(payload)
    return reverse('unique_link', kwargs={'token': token}), token 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:8,代碼來源:utils.py

示例12: generate_confirmation_token

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def generate_confirmation_token(email):
    serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
    return serializer.dumps(email, salt=current_app.config['SECURITY_PASSWORD_SALT']) 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:5,代碼來源:token.py

示例13: confirm_token

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def confirm_token(token, expiration=3600):
    serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
    try:
        email = serializer.loads(
            token,
            salt=current_app.config['SECURITY_PASSWORD_SALT'],
            max_age=expiration
        )
    except:
        return False
    return email 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:13,代碼來源:token.py

示例14: get_state

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def get_state(self):
        serializer = URLSafeTimedSerializer(settings.SECRET_KEY)

        return serializer.dumps(self.get_local_netloc()) 
開發者ID:forcemain,項目名稱:notes,代碼行數:6,代碼來源:weixin_user.py

示例15: verify_weixin_state

# 需要導入模塊: import itsdangerous [as 別名]
# 或者: from itsdangerous import URLSafeTimedSerializer [as 別名]
def verify_weixin_state(self):
        state = self.get_weixin_state()
        try:
            serializer = URLSafeTimedSerializer(settings.SECRET_KEY)
            return serializer.loads(state) == self.get_local_netloc()
        except BadData:
            return False 
開發者ID:forcemain,項目名稱:notes,代碼行數:9,代碼來源:weixin_user.py


注:本文中的itsdangerous.URLSafeTimedSerializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。