本文整理汇总了Python中itsdangerous.JSONWebSignatureSerializer方法的典型用法代码示例。如果您正苦于以下问题:Python itsdangerous.JSONWebSignatureSerializer方法的具体用法?Python itsdangerous.JSONWebSignatureSerializer怎么用?Python itsdangerous.JSONWebSignatureSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itsdangerous
的用法示例。
在下文中一共展示了itsdangerous.JSONWebSignatureSerializer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify_api_key
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def verify_api_key(api_key):
"""Verify an API key based on the user name
Returns:
Actinia Core_api.resources.common.user.ActiniaUser:
A user object is success or None
"""
s = JSONWebSignatureSerializer(global_config.SECRET_KEY)
try:
data = s.loads(api_key)
except BadSignature:
return None
user = ActiniaUser(data["user_id"])
if user.exists():
return user
return None
示例2: test_missing_algorithm_name
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def test_missing_algorithm_name(self):
python_node = self.get_ast_node(
"""
from itsdangerous import JSONWebSignatureSerializer as Serializer
serializer = Serializer(app.config['SECRET_KEY'])
"""
)
linter = dlint.linters.BadItsDangerousKwargUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
示例3: generate_api_key
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_api_key(self):
s = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
byte_str = s.dumps({
'user': str(self.id),
'time': time(),
})
self.apikey = byte_str.decode()
示例4: confirm_login
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [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)
if not user:
return redirect(url_for('logout'))
# 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: generate_api_key
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_api_key(self):
"""Generate an API key based on the user id
Returns:
str:
API key
"""
s = JSONWebSignatureSerializer(global_config.SECRET_KEY)
return s.dumps({"user_id":self.user_id})
示例6: generate_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def generate_token(tenant: Tenant) -> bytes:
s = JSONWebSignatureSerializer(current_app.secret_key, salt="auth")
payload: Dict[str, Any] = {
"access": {str(k): int(v) if v else None for k, v in tenant.access.items()}
}
if getattr(tenant, "user_id", None):
payload["uid"] = str(tenant.user_id)
return s.dumps(payload)
示例7: parse_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def parse_token(token: str) -> Optional[Any]:
s = JSONWebSignatureSerializer(current_app.secret_key, salt="auth")
try:
return s.loads(token)
except BadSignature:
return None
示例8: init_app
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import JSONWebSignatureSerializer [as 别名]
def init_app(app):
if not app.secret_key:
logger.warning("The `SECRET_KEY` setting is not set; tokens will be signed with "
"an insecure, static key")
secret_key = app.secret_key or 'NOT THAT SECRET'
app.tokenauth_serializer = JSONWebSignatureSerializer(secret_key)