本文整理汇总了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
示例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)
示例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
示例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'))
示例5: get_credential
def get_credential(a_token):
s = JSONWebSignatureSerializer(server_secret_key)
try:
credential = s.loads(a_token)
return credential
except:
return None
示例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
示例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
示例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')
示例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
示例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 {}
示例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
示例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 {}
示例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)
示例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
示例15: verify_token
def verify_token(token):
s = SigSerializer(SECRET_KEY)
try:
data = s.loads(token)
except (BadSignature):
return None
return data