def create_access_token(claims, footer=None): token = paseto.create( key=Config()._secret_key, purpose='local', claims=claims, footer=footer, exp_seconds=current_app.config.get('PASETO_EXPIRATION_DELTA')) return token.decode("utf-8")
def create_access_token_public(identity, footer=None): token = paseto.create( key=Config()._private_key, purpose='public', claims=identity, footer=footer, exp_seconds=current_app.config.get('PASETO_EXPIRATION_DELTA')) return token.decode("utf-8")
def test_skip_validation_on_expired(): token = paseto.create(key=private_key, purpose='public', claims={'my claims': [1, 2, 3]}, exp_seconds=-300) parsed = paseto.parse(key=public_key, purpose='public', token=token, validate=False) assert parsed
def test_claim_is_expired(): token = paseto.create(key=private_key, purpose='public', claims={'my claims': [1, 2, 3]}, exp_seconds=-300) with pytest.raises(paseto.PasetoTokenExpired): paseto.parse( key=public_key, purpose='public', token=token, )
def test_exp_claim(): token = paseto.create(key=private_key, purpose='public', claims={'my claims': [1, 2, 3]}, exp_seconds=300) parsed = paseto.parse( key=public_key, purpose='public', token=token, ) assert parsed
def _generate_token(form): key = bytes.fromhex(os.environ["PASETO_PRIVATE_KEY"]) claims = { "user": str(form.view.request.user.account.uuid), "partner": settings.DATABASES["default"]["SCHEMA"], } token = paseto.create(key=key, purpose="public", claims=claims, exp_seconds=300) return token.decode("utf-8")
def test_claim_is_expired(): token = paseto.create(key=private_key, purpose='public', claims=my_claims, exp_seconds=-300) with pytest.raises(BaseException): paseto.parse( key=public_key, purpose='public', token=token, )
def test_create(options): create_params = { 'key': options['key'], 'purpose': options['purpose'], 'claims': options['claims'], 'footer': options['footer'], } token = paseto.create(**create_params) assert token.startswith(options['expected_header'].encode()) parse_key = options.get('public_key', options['key']) parsed = paseto.parse( key=parse_key, purpose=options['purpose'], token=token, ) assert parsed['message'] == options['claims'] assert parsed['footer'] == options['footer']
def test_required_claims(): token = paseto.create(key=private_key, purpose='public', claims={'my claims': [1, 2, 3]}, exp_seconds=-300) parsed = paseto.parse(key=public_key, purpose='public', token=token, validate=False, required_claims=['exp', 'my claims']) assert 'exp' in parsed['message'] assert 'my claims' in parsed['message'] with pytest.raises(paseto.PasetoValidationError): paseto.parse(key=public_key, purpose='public', token=token, validate=False, required_claims=['exp', 'missing'])
def test_required_claims(): token = paseto.create(key=private_key, purpose='public', claims=my_claims, exp_seconds=-300) parsed = paseto.parse(key=public_key, purpose='public', token=token, validate=False, required_claims=['exp', claims_name]) assert 'exp' in parsed['message'] assert 'my claims' in parsed['message'] with pytest.raises(BaseException): paseto.parse(key=public_key, purpose='public', token=token, validate=False, required_claims=['exp', 'missing'])
import paseto import pysodium key = secrets.token_bytes(32) ttl = 60 * 5 data = { 'id': str(uuid.uuid1()), 'name': 'John Doe', 'type': 'super-admin', } token = paseto.create(key=key, purpose='local', claims=data, footer={'check': True}, exp_seconds=ttl) print(f''' Token Data {json.dumps(data, indent = 4)} PASETO {token.decode("utf-8")} ''') parsed_token = paseto.parse(key=key, purpose='local', token=token)