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


Python JSONWebSignatureSerializer.dumps方法代码示例

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


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

示例1: generate_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def generate_token(a_username,a_password):
    if valid_lpirc_session(a_username) is None:
        create_lpirc_session(a_username)
    else:
        # Session already created, nothing to do send previously generated token
        if recycle_db != 1:
            sess = Session.query.filter_by(username=a_username).first()
            token = sess.token
            return token
        else: # Recycle
            # Should be a penalty for multiple login attempts
            delete_lpirc_session(a_username)
            create_lpirc_session(a_username)

    sess = Session.query.filter_by(username=a_username).first()
    s = JSONWebSignatureSerializer(server_secret_key)
    dt = sess.timestamp
    dt_str = dt.strftime(datetime_format)
    print dt_str
    # Adding session created time for timeout validation
    token = s.dumps({ff_username: a_username, ff_password: a_password, ff_timestamp: dt_str})
    # Update session database
    sess.token = token
    if (enable_powermeter == 1) and (a_username != powermeter_user):
        sess.powermeter_status = powermeter_status_stop # So that, it can be restarted later

    if a_username == powermeter_user:
        sess.mytimeout = sys.maxint

    db.session.commit()
    return token
开发者ID:adam-erickson,项目名称:LPIRC,代码行数:33,代码来源:referee.py

示例2: hmac

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def hmac(payload, private_key):
    '''Generate a decryptable signature on the server side that the client
    can analzye. Server generated HMAC signatures aren't timed.
    '''
    payload = organize_payload(payload)
    t = Token(secret_key=private_key)
    return t.dumps(payload)
开发者ID:bbuneci,项目名称:OpenWebAmp,代码行数:9,代码来源:keys.py

示例3: confirm_login

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def confirm_login():
    # Check for state and for 0 errors
    state = session.get('oauth2_state')
    if not state or request.values.get('error'):
        return redirect(url_for('index'))

    # Fetch token
    discord = make_session(state=state)
    discord_token = discord.fetch_token(
        TOKEN_URL,
        client_secret=OAUTH2_CLIENT_SECRET,
        authorization_response=request.url)
    if not discord_token:
        return redirect(url_for('index'))

    # Fetch the user
    user = get_user(discord_token)
    # Generate api_key from user_id
    serializer = JSONWebSignatureSerializer(app.config['SECRET_KEY'])
    api_key = str(serializer.dumps({'user_id': user['id']}))
    # Store api_key
    db.set('user:{}:api_key'.format(user['id']), api_key)
    # Store token
    db.set('user:{}:discord_token'.format(user['id']), json.dumps(discord_token))
    # Store api_token in client session
    api_token = {
        'api_key': api_key,
        'user_id': user['id']
    }
    session.permanent = True
    session['api_token'] = api_token
    return redirect(url_for('select_server'))
开发者ID:Hatsuney,项目名称:mee6,代码行数:34,代码来源:app.py

示例4: generate_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def generate_token(user):
    secret_key = get_secret_key()
    s = JSONWebSignatureSerializer(secret_key)
    expired_at = utcnow().replace(hours=+2).timestamp
    d = {'user': user, 'expired_at': expired_at}
    token = s.dumps(d).decode('utf-8')
    return token, d
开发者ID:nl-seoultech,项目名称:tento-server,代码行数:9,代码来源:auth.py

示例5: generate_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
 def generate_token(self):
     JWT = JWS(os.environ.get('SECRET_KEY'))
     return JWT.dumps({
         "id": self.id,
         "username": self.username,
         # 2 hrs expiration
         "expires": (datetime.datetime.now() +
                     datetime.timedelta(seconds=2*60*60)).timestamp()
         }).decode('utf-8')
开发者ID:ishankhare07,项目名称:wingify-challenge,代码行数:11,代码来源:users.py

示例6: af_reset_send

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
    def af_reset_send(cls_, email, returnurl):
        user = cls_.find_first({'email': email})
        if not user:
            raise ApiValidationError(ValidationError('Unknown email'))

        serializer = JSONWebSignatureSerializer(current_app.config['API_KEY'])
        resettoken = serializer.dumps({"id": user.id, "signature": user.signature}).decode('utf-8')
        content = 'Click here to reset your password: %s' % (returnurl + resettoken)
        mailer.send(user.email, user.name, 'Password reset link', content)
        return {'success': True}
开发者ID:eoglethorpe,项目名称:sidr,代码行数:12,代码来源:user.py

示例7: test_invalid_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def test_invalid_token(f_session, f_user):
    secret_key = get_secret_key()
    s = JSONWebSignatureSerializer(secret_key)
    expired_at = arrow.utcnow().replace(hours=-2).timestamp
    d = {
        'user': {'id': f_user.id, 'email': f_user.email, 'name': f_user.name},
        'expired_at': expired_at
    }
    token = s.dumps(d).decode('utf-8')
    with raises(InvalidTokenError):
        t = validate_token('dadfa.asdf')
    with raises(ExpiredTokenError):
        t = validate_token(token)
开发者ID:nl-seoultech,项目名称:tento-server,代码行数:15,代码来源:test_web_login.py

示例8: post

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
    def post(self):
        serializer = JSONWebSignatureSerializer(
            current_app.config['API_KEY'])
        args = validator.validate(self.get_request())

        user = models.User.find_first({'email': args['email']})
        if user is None or user.password != args['password']:
            raise ApiError("Wrong email or password provided for {}".format(args['email']))

        if user.status is not const.STATUS_ACTIVE:
            raise ApiError("User is not active")

        token = serializer.dumps({"id": user.id, "signature": user.signature}).decode('utf-8')
        return self.respond({"token": token, "user": user.jsonify(user)})
开发者ID:eoglethorpe,项目名称:sidr,代码行数:16,代码来源:auth.py

示例9: generate_csrf_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
    def generate_csrf_token():
        nonce = os.urandom(16)
        secret = session.setdefault('_csrf_secret', os.urandom(16))

        nonce_int = bytes_to_int(nonce)
        secret_int = bytes_to_int(secret)

        jsw = JSONWebSignatureSerializer(app.secret_key)
        token = jsw.dumps({
            "n": b64encode(nonce),
            "k": b64encode(int_to_bytes(nonce_int ^ secret_int))
        })

        return token
开发者ID:quru,项目名称:flask-csrf,代码行数:16,代码来源:csrf.py

示例10: post

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
    def post(self, request):
        username = request.body.get("username", "")
        password = request.body.get("password", "")
        user = user_actions.get_by_username_and_password(username, password)
        if not user:
            return responses.BadRequest({"error": "Invalid username or password"})
        else:
            token_data = {"user_id": user.id}
            serializer = JSONWebSignatureSerializer(settings.SECRET_KEY)
            token = serializer.dumps(token_data).decode("ascii")

            result = to_plain(user, ignore_fields=["id", "password"])
            result["token"] = token
            return responses.Ok(result)
开发者ID:PIWEEK,项目名称:piweekr-back,代码行数:16,代码来源:user_handlers.py

示例11: generate_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def generate_token(a_username,a_password):
    if valid_lpirc_session(a_username) is None:
        create_lpirc_session(a_username)
    else:
        # Should be a penalty for multiple login attempts
        delete_lpirc_session(a_username)
        create_lpirc_session(a_username)

    sess = Session.query.filter_by(username=a_username).first()
    s = JSONWebSignatureSerializer(server_secret_key)
    dt = sess.timestamp
    dt_str = dt.strftime(datetime_format)
    print dt_str
    # Adding session created time for timeout validation
    token = s.dumps({ff_username: a_username, ff_password: a_password, ff_timestamp: dt_str})
    return token
开发者ID:jamesli21,项目名称:LPIRC,代码行数:18,代码来源:referee.py

示例12: voucher

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def voucher():
    test_dict = {
        'email': '[email protected]',
        'card': '123456789012345678901234567890',
        'charity': 20,
        'content': 80,
        'amount': 25
                }
    s = JSONWebSignatureSerializer('secret', algorithm_name='HS512')
    res = s.dumps(test_dict)
    print(res)
    l = s.loads(res)
    print(l)

# send_mail('[email protected]', 'dasa' ,'asdasfadfada')
# voucher()
开发者ID:PashaShulga,项目名称:webapp,代码行数:18,代码来源:voucher.py

示例13: patch

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
    def patch(self, request, username):
        user = load_user(username)
        check_user_is_self(request.user, user)

        validator = user_validators.UserForUpdateValidator(request.body)
        if validator.is_valid():
            user = user_actions.update_user(
                user,
                user_entities.UserForUpdate(**validator.cleaned_data)
            )

            token_data = {"user_id": user.id}
            serializer = JSONWebSignatureSerializer(settings.SECRET_KEY)
            token = serializer.dumps(token_data).decode("ascii")

            result = to_plain(user, ignore_fields=["id", "password"])
            result["token"] = token
            return responses.Ok(result)
        else:
            return responses.BadRequest(validator.errors)
开发者ID:PIWEEK,项目名称:piweekr-back,代码行数:22,代码来源:user_handlers.py

示例14: create_load_more_url

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def create_load_more_url(kwargs):
    ''' create the url for load more button in event listing page
    arg:
        kwargs: kwargs contain the different type of data
    return:
        url for the load more button
    '''
    s = PageSerializer(config.SECRET_KEY)
    # check for the cur is present or not
    # if cur is present that means load more button request
    # in that case page number will increment
    # othewise new request the assign page no 2
    try:
        # get previous page number
        prev = get_event_page_no(kwargs['cur'])
        page = prev + 1
    except:
        page = 2
    kwargs['cur'] = s.dumps(page)
    return url_for('event', **kwargs)
开发者ID:aman0511,项目名称:91events,代码行数:22,代码来源:helpers.py

示例15: generate_token

# 需要导入模块: from itsdangerous import JSONWebSignatureSerializer [as 别名]
# 或者: from itsdangerous.JSONWebSignatureSerializer import dumps [as 别名]
def generate_token():

    """ Access Token """
    access_token_serializer = TimedJSONWebSignatureSerializer(
                            app.config['SECRET_KEY'],
                            expires_in=app.config['EXPIRES_IN'])

    """ Secret Token """
    secret_token_serializer = JSONWebSignatureSerializer(
                            app.config['SECRET_KEY'])

    d = {'username': g.user.username, 'password': g.user.password}

    d_access = d.copy()
    d_access.update({'secret': False})

    d_secret = d.copy()
    d_secret.update({'secret': True})

    access_token = access_token_serializer.dumps(d_access)
    secret_token = secret_token_serializer.dumps(d_secret)

    return access_token, secret_token
开发者ID:NurFaizin,项目名称:SDP,代码行数:25,代码来源:simplelogin_token.py


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