swt 0.2.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
{swt-0.2.0 → swt-0.5.0}/PKG-INFO
RENAMED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: swt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Simple Web Token library for Python
|
|
5
|
-
Home-page: https://github.com/davidolrik/python-swt
|
|
6
5
|
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
7
|
Keywords: swt
|
|
8
8
|
Author: David Jack Wange Olrik
|
|
9
9
|
Author-email: david@olrik.dk
|
|
10
|
-
Requires-Python: >=3.
|
|
10
|
+
Requires-Python: >=3.13,<4.0
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
|
|
18
|
-
Requires-Dist: poetry-version (>=0.
|
|
19
|
-
Requires-Dist: pycryptodome (>=3.
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Provides-Extra: docs
|
|
18
|
+
Requires-Dist: poetry-version (>=0.2.0,<0.3.0)
|
|
19
|
+
Requires-Dist: pycryptodome (>=3.23.0,<4.0.0)
|
|
20
|
+
Requires-Dist: sphinx (>=9.1.0,<10.0.0) ; extra == "docs"
|
|
21
|
+
Requires-Dist: sphinx_rtd_theme (>=3.1.0,<4.0.0) ; extra == "docs"
|
|
20
22
|
Project-URL: Documentation, https://python-swt.readthedocs.io/
|
|
23
|
+
Project-URL: Homepage, https://github.com/davidolrik/python-swt
|
|
21
24
|
Project-URL: Repository, https://github.com/davidolrik/python-swt
|
|
22
25
|
Description-Content-Type: text/markdown
|
|
23
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "swt"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "Simple Web Token library for Python"
|
|
5
5
|
authors = ["David Jack Wange Olrik <david@olrik.dk>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -18,23 +18,27 @@ packages = [
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[tool.poetry.dependencies]
|
|
21
|
-
python = "
|
|
22
|
-
pycryptodome = "^3.
|
|
23
|
-
poetry-version = "^0.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
pytest-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
python = ">=3.13,<4.0"
|
|
22
|
+
pycryptodome = "^3.23.0"
|
|
23
|
+
poetry-version = "^0.2.0"
|
|
24
|
+
sphinx = {version = "^9.1.0", optional = true}
|
|
25
|
+
sphinx_rtd_theme = {version = "^3.1.0", optional = true}
|
|
26
|
+
|
|
27
|
+
[tool.poetry.extras]
|
|
28
|
+
docs = ["sphinx", "sphinx_rtd_theme"]
|
|
29
|
+
|
|
30
|
+
[tool.poetry.group.dev.dependencies]
|
|
31
|
+
pytest = "^9.0.2"
|
|
32
|
+
coverage = {extras = ["toml"], version = "^7.13.4"}
|
|
33
|
+
pytest-cov = "^7.0.0"
|
|
34
|
+
sphinx = "^9.1.0"
|
|
35
|
+
sphinx_rtd_theme = "^3.1.0"
|
|
36
|
+
towncrier = "^25.8.0"
|
|
37
|
+
pytest-ruff = "^0.5"
|
|
38
|
+
|
|
39
|
+
[tool.pytest]
|
|
40
|
+
minversion = "9.0"
|
|
41
|
+
addopts = ["--cov", "--cov-report=xml", "--ruff", "--ruff-format"]
|
|
38
42
|
|
|
39
43
|
[tool.coverage.paths]
|
|
40
44
|
source = ["src", "*/site-packages"]
|
swt-0.2.0/setup.py
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
package_dir = \
|
|
5
|
-
{'': 'src'}
|
|
6
|
-
|
|
7
|
-
packages = \
|
|
8
|
-
['swt']
|
|
9
|
-
|
|
10
|
-
package_data = \
|
|
11
|
-
{'': ['*']}
|
|
12
|
-
|
|
13
|
-
install_requires = \
|
|
14
|
-
['poetry-version>=0.1.5,<0.2.0', 'pycryptodome>=3.9.7,<4.0.0']
|
|
15
|
-
|
|
16
|
-
setup_kwargs = {
|
|
17
|
-
'name': 'swt',
|
|
18
|
-
'version': '0.2.0',
|
|
19
|
-
'description': 'Simple Web Token library for Python',
|
|
20
|
-
'long_description': '# Python SWT Library\n\n\n\n\n\n\n\nPython library for handling `Simple Web Tokens`.\n\n## Documentation\n\nYou can find the docs [here](https://python-swt.readthedocs.io/).\n\n## Caveats\n\n- Please use `pycryptodome` and not `pycrypto` as the later is unmaintained and\n broken on python 3.8+\n- Currently only supports RSA-SHA256\n\n## TODO\n\n- Add support HMAC SHA256\n- Add Raises: KeyNotFoundError to sign()\n',
|
|
21
|
-
'author': 'David Jack Wange Olrik',
|
|
22
|
-
'author_email': 'david@olrik.dk',
|
|
23
|
-
'maintainer': None,
|
|
24
|
-
'maintainer_email': None,
|
|
25
|
-
'url': 'https://github.com/davidolrik/python-swt',
|
|
26
|
-
'package_dir': package_dir,
|
|
27
|
-
'packages': packages,
|
|
28
|
-
'package_data': package_data,
|
|
29
|
-
'install_requires': install_requires,
|
|
30
|
-
'python_requires': '>=3.7,<4.0',
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setup(**setup_kwargs)
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
> __version__ = '0.1.0'
|
|
2
|
-
|
|
3
|
-
> from Crypto.PublicKey import RSA
|
|
4
|
-
> from Crypto.Signature import PKCS1_v1_5
|
|
5
|
-
> from Crypto.Hash import SHA256
|
|
6
|
-
> from urllib.parse import parse_qsl, unquote
|
|
7
|
-
> from base64 import b64decode
|
|
8
|
-
> import time
|
|
9
|
-
> from os import listdir, getcwd
|
|
10
|
-
> from pathlib import Path
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
> class SWT:
|
|
14
|
-
> def __init__(self, token=None):
|
|
15
|
-
# Assume the worst
|
|
16
|
-
! self.token_is_signed = False
|
|
17
|
-
! self.token_is_expired = True
|
|
18
|
-
|
|
19
|
-
# Internal data
|
|
20
|
-
! self.token_raw = None
|
|
21
|
-
! self.token_claims = {}
|
|
22
|
-
|
|
23
|
-
# If called with a token, set and verify
|
|
24
|
-
! if token is not None:
|
|
25
|
-
! self.token(token)
|
|
26
|
-
|
|
27
|
-
> @property
|
|
28
|
-
> def is_valid(self):
|
|
29
|
-
! return not self.token_is_expired and self.token_is_signed
|
|
30
|
-
|
|
31
|
-
> @property
|
|
32
|
-
> def is_expired(self):
|
|
33
|
-
! return self.token_is_expired
|
|
34
|
-
|
|
35
|
-
> @property
|
|
36
|
-
> def is_signed(self):
|
|
37
|
-
! return self.token_is_signed
|
|
38
|
-
|
|
39
|
-
> def __bool__(self):
|
|
40
|
-
! return self.is_valid
|
|
41
|
-
|
|
42
|
-
> def __str__(self):
|
|
43
|
-
! value = (
|
|
44
|
-
! f"SWT:[Issuer={self.token_claims.get('Issuer','unknown')} sub={self.token_claims.get('sub','unknown')} "
|
|
45
|
-
! f"valid={self.is_valid} signed={self.is_signed} expired={self.is_expired} "
|
|
46
|
-
! f"expire_date={time.strftime('%Y-%m-%dT%H:%M:%S%z', time.localtime(int(self.token_claims.get('ExpiresOn','0'))))}]"
|
|
47
|
-
! )
|
|
48
|
-
! return value
|
|
49
|
-
|
|
50
|
-
> def token(self, token):
|
|
51
|
-
# Allow caller to take http header and parse it directly to us
|
|
52
|
-
! self.token_raw = token.replace('Bearer ', '')
|
|
53
|
-
|
|
54
|
-
# Split token into data and signature
|
|
55
|
-
! self.token_data, self.token_signature = self.token_raw.rsplit(
|
|
56
|
-
! '&RSASHA256=')
|
|
57
|
-
! print(f"Data: {self.token_data}")
|
|
58
|
-
! print(f"Signature: {self.token_signature}")
|
|
59
|
-
|
|
60
|
-
# Convert to internal format
|
|
61
|
-
! self.token_signature_raw = b64decode(unquote(self.token_signature))
|
|
62
|
-
! self.token_claims = dict(parse_qsl(self.token_data))
|
|
63
|
-
|
|
64
|
-
# Make sure we have a signature
|
|
65
|
-
! if self.token_signature is None or not self.token_signature:
|
|
66
|
-
! self.signature_is_valid = False
|
|
67
|
-
! return
|
|
68
|
-
|
|
69
|
-
# Load public key
|
|
70
|
-
! self.public_key = Path(
|
|
71
|
-
! f'stskeys/{self.token_claims["Issuer"]}-publickey.pem').read_text()
|
|
72
|
-
|
|
73
|
-
# Validate signature
|
|
74
|
-
! rsa_key = RSA.importKey(self.public_key)
|
|
75
|
-
! signer = PKCS1_v1_5.new(rsa_key)
|
|
76
|
-
! digest = SHA256.new(self.token_data.encode('utf8'))
|
|
77
|
-
! if signer.verify(digest, self.token_signature_raw):
|
|
78
|
-
! self.token_is_signed = True
|
|
79
|
-
! print("Signature is valid")
|
|
80
|
-
|
|
81
|
-
# Check expire date
|
|
82
|
-
! if int(self.token_claims.get('ExpiresOn', 0)) < int(time.time()):
|
|
83
|
-
! print("Token is expired")
|
|
84
|
-
! self.token_is_expired = True
|
{swt-0.2.0 → swt-0.5.0}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|