本文整理匯總了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)