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


Python itsdangerous.JSONWebSignatureSerializer类代码示例

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


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

示例1: decode_auth_token

def decode_auth_token(token):
    try:
        s = JSONWebSignatureSerializer(app.secret_key)
        print token 
        return s.loads(token)
    except:
        return None
开发者ID:olymk2,项目名称:stomatopod,代码行数:7,代码来源:api.py

示例2: reset_password

def reset_password(token):

    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('admin.home'))

    s = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])

    data = None

    try:
        data = s.loads(token)
    except:
        abort(404)

    if data.get('id'):
        id = data.get('id')
    else:
        id = 0

    user = User.query.get_or_404(id)

    form = ResetForm()

    if form.validate_on_submit():
        user.password = form.password.data.strip()
        db.session.add(user)
        db.session.commit()
        flash('Your password has now been reset.')
        return redirect(url_for('main.login'))

    return render_template('reset.html', title='Reset Password', form=form, user=user, token=token)
开发者ID:MattHealy,项目名称:MovieDatabase,代码行数:31,代码来源:views.py

示例3: get_by_authorization

 def get_by_authorization(self_class, token, svc_account):
     if token:
         token = token.replace('Basic ', '', 1)
         s = JSONWebSignatureSerializer(flask.current_app.config['SECRET_KEY'])
         data = s.loads(token)
         return User.get(data['id'], svc_account)
     return None
开发者ID:followcat,项目名称:cloudshare,代码行数:7,代码来源:account.py

示例4: confirm_login

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,代码行数:32,代码来源:app.py

示例5: get_credential

def get_credential(a_token):
    s = JSONWebSignatureSerializer(server_secret_key)
    try:
        credential = s.loads(a_token)
        return credential
    except:
        return None
开发者ID:adam-erickson,项目名称:LPIRC,代码行数:7,代码来源:referee.py

示例6: generate_token

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,代码行数:31,代码来源:referee.py

示例7: generate_token

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,代码行数:7,代码来源:auth.py

示例8: confirm

def confirm(token):

    if g.user.is_confirmed():
        return redirect(url_for('admin.home'))

    s = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])

    data = None

    try:
        data = s.loads(token)
    except:
        abort(404)

    if data.get('id'):
        id = data.get('id')
    else:
        id = 0

    user = User.query.get_or_404(id)

    if user.id == g.user.id:
        user.confirmed = True
        db.session.add(user)
        db.session.commit()
        flash('You have successfully confirmed your account!')
    else:
        flash('Invalid token')

    return render_template("admin/confirm.html", title='Confirm Account')
开发者ID:MattHealy,项目名称:MovieDatabase,代码行数:30,代码来源:views.py

示例9: verify_group_token

 def verify_group_token(token):
     s = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
     try:
         data = s.loads(token)
     except:
         return None
     group = Group.query.get(data['id'])
     return group
开发者ID:WesTheWes,项目名称:SaveTheDate,代码行数:8,代码来源:models.py

示例10: unsign

 def unsign(self, value):
     if value is None:
         return value
     s = JSONWebSignatureSerializer(self.secret_key, algorithm_name='HS256')
     try:
         return s.loads(value)
     except BadSignature:
         return {}
开发者ID:jiaxiangkong,项目名称:jumpserver,代码行数:8,代码来源:encode.py

示例11: verify_auth_token

 def verify_auth_token(token):
     s = JSONWebSignatureSerializer(app.config['SECRET_KEY'])
     try:
         data = s.loads(token)
     except BadSignature:
         return None
     user = User.query.get(data['id'])
     return user
开发者ID:njuwangchen,项目名称:xiaomanfenAPI,代码行数:8,代码来源:models.py

示例12: unsign

 def unsign(self, value):
     if value is None:
         return value
     s = JSONWebSignatureSerializer(self.secret_key)
     try:
         return s.loads(value)
     except BadSignature:
         return {}
开发者ID:achachadra7,项目名称:jumpserver,代码行数:8,代码来源:utils.py

示例13: hmac

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,代码行数:7,代码来源:keys.py

示例14: VerifyToken

def VerifyToken(token, secret):
    s = Serializer(secret)
    try:
        data = s.loads(token)
    except BadSignature as e:
        raise InvalidAuth('bad_token', e.message)
    return data
开发者ID:cloew,项目名称:KaoFlaskAuth,代码行数:7,代码来源:token_builder.py

示例15: verify_token

def verify_token(token):
    s = SigSerializer(SECRET_KEY)
    try:
        data = s.loads(token)
    except (BadSignature):
        return None
    return data
开发者ID:Kim-Duck-Hyun,项目名称:PJ_Shout,代码行数:7,代码来源:auth.py


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