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


Python itsdangerous.Signer类代码示例

本文整理汇总了Python中itsdangerous.Signer的典型用法代码示例。如果您正苦于以下问题:Python Signer类的具体用法?Python Signer怎么用?Python Signer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Signer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cookie_serialize

def cookie_serialize(secure_key, session_id, expire):
    """Serialize the cookie. Set the expire_time timestamp into the cookie"""
    signer = Signer(secure_key)
    session_data = session_id.encode('utf-8') + '&' + str(expire)

    session_data = signer.sign(session_data).decode('utf-8')
    return session_data
开发者ID:AliceLanniste,项目名称:Puck,代码行数:7,代码来源:cookies.py

示例2: gen_signed_code

 def gen_signed_code(self, identifier=None):
     """Generates a signed code in the format discount_code_base.randint.signature"""
     if not identifier:
         identifier = buid()
     signer = Signer(self.secret)
     key = "{base}.{identifier}".format(base=self.discount_code_base, identifier=identifier)
     return signer.sign(key)
开发者ID:hasgeek,项目名称:boxoffice,代码行数:7,代码来源:discount_policy.py

示例3: build_url

    def build_url(self, local_path, **kwargs):

        local_path = local_path.strip('/')

        for key in 'background mode width height quality format padding'.split():
            if key in kwargs:
                kwargs[key[0]] = kwargs.pop(key)
        
        # Remote URLs are encoded into the query.
        parsed = urlparse(local_path)
        if parsed.netloc:
            kwargs['u'] = local_path
            local_path = 'remote'

        # Local ones are not.
        else:
            abs_path = self.find_img(local_path)
            if abs_path:
                kwargs['v'] = encode_int(int(os.path.getmtime(abs_path)))
        
        # Sign the query.
        public_kwargs = ((k, v) for k, v in kwargs.iteritems() if not k.startswith('_'))
        query = urlencode(sorted(public_kwargs), True)
        signer = Signer(current_app.secret_key)
        sig = signer.get_signature('%s?%s' % (local_path, query))

        return '%s/%s?%s&s=%s' % (
            current_app.config['IMAGES_URL'],
            local_path,
            query,
            sig,
        )
开发者ID:iurisilvio,项目名称:Flask-Images,代码行数:32,代码来源:flask_images.py

示例4: save_session

    def save_session(self, app, session, response):
        domain = self.get_cookie_domain(app)
        path = self.get_cookie_path(app)
        if not session:
            if session.modified:
                self.redis.delete(self.session_prefix + session.session_id)
                response.delete_cookie(app.session_cookie_name,
                                       domain=domain, path=path)
            return

        httponly = self.get_cookie_httponly(app)
        secure = self.get_cookie_secure(app)
        expire = self.get_expiration_time(app, session)
        serialize_session = self.serialization_method.dumps(dict(session))
        pipe = self.redis.pipeline()
        pipe.set(self.session_prefix + session.session_id, serialize_session)
        pipe.expire(self.session_prefix + session.session_id, total_seconds(self.expire_time))
        pipe.execute()

        if self.use_sign:
            session_id = Signer(app.secret_key, salt='flask-redis-session',
                                key_derivation='hmac').sign(session.session_id.encode('utf-8'))
            session_id = session_id.decode('utf-8')

        else:
            session_id = session.session_id
            print('session_id:', session_id)
        response.set_cookie(key=app.session_cookie_name, value=session_id,
                            max_age=self.expire_time, expires=expire,
                            path=path, domain=domain,
                            secure=secure, httponly=httponly)
开发者ID:rtx3,项目名称:Salt-MWDS,代码行数:31,代码来源:redissession.py

示例5: validate_machine_token

 def validate_machine_token(self, token):
     s = Signer(self.secret)
     try:
         s.unsign(token)
         return True
     except BadSignature:
         return False
开发者ID:agmenut,项目名称:sabotage2_revamp,代码行数:7,代码来源:models.py

示例6: reset_password

def reset_password():
    form = ResetPasswordForm(request.form)

    if request.method == "POST" and form.validate():
        token = form.token.data

        s = Signer(app.config['SECRET_KEY'])

        try:
            email = s.unsign(token)
        except BadSignature:
            return render_template("reset_invalid_token.html")

        user = User.query.filter_by(email=email).first()

        if user:
            user.set_password(form.password.data)

            print user.password

            login_user(user)

            return redirect("/")
        else:
            return render_template("reset_invalid_token.html")

    token = request.args.get('token', None)

    if not token:
        return render_template("reset_invalid_token.html")

    return render_template("reset_password.html", form=form, token=token)
开发者ID:aliyarahman,项目名称:student-application,代码行数:32,代码来源:views.py

示例7: sign

def sign():
    s = Signer(
            bytes(input("Enter a secret(!!) key: "),
                encoding="UTF-8"))
    print(s.sign(
            bytes(input("Enter data\n"),
                encoding="UTF-8")).decode('UTF-8'))
开发者ID:team-code,项目名称:pentest-orchestration,代码行数:7,代码来源:quicksign.py

示例8: validate_fingerprints

def validate_fingerprints(fp_secret_key, fp_salt, client_ip_fingerprint, browser_fingerprint, client_ip, user_agent,
                          accept_language):
    is_valid = True

    signer = Signer(fp_secret_key, fp_salt)

    logging.debug('client_ip_fingerprint: %s', client_ip_fingerprint)
    calculated_client_ip_fingerprint = signer.get_signature(client_ip)
    logging.debug('calculated_client_ip_fingerprint: %s', calculated_client_ip_fingerprint)

    if calculated_client_ip_fingerprint != client_ip_fingerprint:
        logging.warn('Client IP does not match fingerprint in signature')
        is_valid = False

    # TODO:
    # Uncomment return line below until atmobeta sends the right fingerprint signature.
    # Just ignore fingerprint for now.
    return is_valid

    browser_fingerprint_input = ''.join([
        user_agent,
        accept_language])
    logging.debug('browser_fingerprint_input: %s', browser_fingerprint_input)
    logging.debug('browser_fingerprint: %s', browser_fingerprint)
    calculated_browser_fingerprint = signer.get_signature(browser_fingerprint_input)
    logging.debug('calculated_browser_fingerprint: %s', calculated_browser_fingerprint)

    if calculated_browser_fingerprint != browser_fingerprint:
        logging.warn('Browser fingerprint does not match calculated fingerprint')
        is_valid = False

    return is_valid
开发者ID:lenards,项目名称:nginx_novnc_auth,代码行数:32,代码来源:signatures.py

示例9: test_malformed_timestamp

    def test_malformed_timestamp(self, signer):
        other = Signer("secret-key")
        signed = other.sign(b"value.____________")

        with pytest.raises(BadTimeSignature) as exc_info:
            signer.unsign(signed)

        assert "Malformed" in str(exc_info.value)
开发者ID:pallets,项目名称:itsdangerous,代码行数:8,代码来源:test_timed.py

示例10: test_timestamp_missing

    def test_timestamp_missing(self, signer):
        other = Signer("secret-key")
        signed = other.sign("value")

        with pytest.raises(BadTimeSignature) as exc_info:
            signer.unsign(signed)

        assert "missing" in str(exc_info.value)
开发者ID:pallets,项目名称:itsdangerous,代码行数:8,代码来源:test_timed.py

示例11: verify_email

def verify_email(addr):
    s = Signer(app.config['SECRET_KEY'])
    token = s.sign(addr)
    text = """Please click the following link to confirm your email address for {}: {}""".format(
        get_config('ctf_name'),
        url_for('auth.confirm_user', _external=True) + '/' + token.encode('base64')
    )
    sendmail(addr, text)
开发者ID:molecul,项目名称:qa-training-frontend,代码行数:8,代码来源:utils.py

示例12: check_token

 def check_token(token):
     signer = Signer(flask.current_app.config["SECRET_KEY"])
     try:
         id = int(signer.unsign(token).decode("ascii"))
     except Exception as e:
         return None
     user = Subscriber.query.filter_by(id=id).first()
     return user
开发者ID:dfm,项目名称:ArXivMailer,代码行数:8,代码来源:models.py

示例13: generate_csrf_token

def generate_csrf_token(user):
    """产生token"""
    secret_key = current_app.config.get("WTF_CSRF_SECRET_KEY", current_app.secret_key)
    nonce = os.urandom(24)
    user_id = user.id
    signer = Signer(secret_key)
    csrf_token = signer.sign(str(user_id))
    print csrf_token
    return csrf_token
开发者ID:kinorsi,项目名称:Luyasi-Flask,代码行数:9,代码来源:helpers.py

示例14: attachment

 def attachment(self, att_id):
     s = Signer(current_app.config.get('SECRET_KEY'), sep='$')
     try:
         att_id = int(s.unsign(att_id))
         attach_obj = self.model.client.model('ir.attachment')
         content = attach_obj.read(att_id, ['datas'])['datas']
         image_fp = StringIO(base64.b64decode(content))
         return send_file(image_fp)
     except BadSignature:
         abort(404)
开发者ID:gisce,项目名称:flask-admin-openerp,代码行数:10,代码来源:__init__.py

示例15: split_cookie

    def split_cookie(self, rv):
        signer = Signer(self.app.secret_key)
        cookie_data = rv.headers['Set-Cookie'].split(';', 1)[0]

        for cookie in cookie_data.split('&'):
            name, value = cookie_data.split('=')

            if name == self.app.session_cookie_name:
                unsigned_value = signer.unsign(value)
                return unsigned_value.split('_')
开发者ID:Scarygami,项目名称:gae-gcs-push2deploy-secrets,代码行数:10,代码来源:test_flask_kvsession.py


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