Python itsdangerous.JSONWebSignatureSerializer() Examples
The following are 8
code examples of itsdangerous.JSONWebSignatureSerializer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
itsdangerous
, or try the search function
.
Example #1
Source File: user.py From actinia_core with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: test_bad_itsdangerous_kwarg_use.py From dlint with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: models.py From udata with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #4
Source File: app.py From mee6 with MIT License | 5 votes |
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'))
Example #5
Source File: user.py From actinia_core with GNU General Public License v3.0 | 5 votes |
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})
Example #6
Source File: auth.py From zeus with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: auth.py From zeus with Apache License 2.0 | 5 votes |
def parse_token(token: str) -> Optional[Any]: s = JSONWebSignatureSerializer(current_app.secret_key, salt="auth") try: return s.loads(token) except BadSignature: return None
Example #8
Source File: tokenstr.py From build-relengapi with Mozilla Public License 2.0 | 5 votes |
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)