How to use the itsdangerous.JSONWebSignatureSerializer function in itsdangerous

To help you get started, we’ve selected a few itsdangerous examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zenodo / zenodo / zenodo / modules / accessrequests / testsuite / test_tokens.py View on Github external
def test_encryption(self):
        """Test that token is not encrypted."""
        s = self.TestSerializer()
        t1 = s.create_token(1, dict(recid=1))
        self.assertRaises(
            BadData,
            JSONWebSignatureSerializer('anotherkey').loads,
            t1
        )
github facebookarchive / CommunityCellularManager / cloud / endagaweb / models.py View on Github external
def generate_jwt(self, data_dict):
        """Generate a JSON web token for this BTS.

        IMPORTANT: This is subject to replay attacks if there's not a nonce in
        the JWT. It's the callers responsibility to include this in the data
        dict if replay attacks are a concern (a random, unique msgid would
        suffice).
        """
        serializer = itsdangerous.JSONWebSignatureSerializer(self.secret)
        return serializer.dumps(data_dict)
github facebookarchive / CommunityCellularManager / client / core / federer_handlers / common.py View on Github external
def check_signed_params(self, jwt_data):
        """
        Decodes the params, makes sure they pass signature (i.e., are valid),
        and then checks that we haven't seen the msgid before. Raises a
        ValueError if errors, else returns True.

        TODO(matt): this particular method seems to be unused (not so the one
                    in federer_handlers.config.config).
        """
        s = itsdangerous.JSONWebSignatureSerializer(self.conf['bts_secret'])
        try:
            data = s.loads(jwt_data)
        except itsdangerous.BadSignature:
            logger.error("Bad jwt signature for request, ignoring.")
            raise ValueError("Bad signature")

        # make sure the msg hasn't been seen before, if so, discard it
        if "msgid" in data:
            if self.msgid_db.seen(str(data['msgid'])):
                logger.error("Endaga: Repeat msgid: %s" % (data['msgid'],))
                raise ValueError("Repeat msgid: %s" % (data['msgid'],))
        else:
            logger.error("Endaga: No message ID.")
            raise ValueError("No message ID.")

        return data
github prkng / api / prkng / models / users.py View on Github external
def generate_apikey(email):
        """
        Generate a user API key
        """
        serial = JSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
        return serial.dumps({
            'email': email,
            'time': time.time()
        })
github jumpserver / jumpserver / apps / common / utils.py View on Github external
def sign(self, value):
        s = JSONWebSignatureSerializer(self.secret_key, algorithm_name='HS256')
        return s.dumps(value).decode()
github hamx0r / ibrest / app / globals.py View on Github external
from ib.opt import ibConnection
import itsdangerous
__author__ = 'Jason Haury'


# ---------------------------------------------------------------------
# CONFIGURATION
# ---------------------------------------------------------------------
# Use environment variables
ibgw_host = os.getenv('IBGW_PORT_4003_TCP_ADDR', os.getenv('IBGW_HOST', '127.0.0.1'))
ibgw_port = int(os.getenv('IBGW_PORT_4003_TCP_PORT', os.getenv('IBGW_PORT', '4003')))  # Use 7496 for TWS
client_id = int(os.getenv('IBGW_CLIENT_ID', 0))  # Use a unique value for each IBREST instance you connect to same TWS

# Beacon globals
id_secret_key = os.getenv('ID_SECRET_KEY', None)
serializer = itsdangerous.JSONWebSignatureSerializer(id_secret_key, salt='beacon') if id_secret_key else None
beacon_last_token = None
beacon_current_token = None
current_ip = None

timeout = 20  # Max loops

# Mutables
managedAccounts = set()
clientId_in_use = False
client_connection = ibConnection(ibgw_host, ibgw_port, client_id)
getting_order_id = False
orderId = 0
tickerId = 0


# ---------------------------------------------------------------------
github jumpserver / jumpserver / apps / common / utils / encode.py View on Github external
def sign(self, value):
        s = JSONWebSignatureSerializer(self.secret_key, algorithm_name='HS256')
        return s.dumps(value).decode()
github getway / diting / apps / common / utils.py View on Github external
def unsign(self, value):
        s = JSONWebSignatureSerializer(self.secret_key)
        try:
            return s.loads(value)
        except BadSignature:
            return {}