usso 0.4.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.
usso-0.4.0/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 The Python Packaging Authority (PyPA)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
usso-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: usso
3
+ Version: 0.4.0
4
+ Summary: A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices.
5
+ Author-email: Mahdi Kiani <mahdikiany@gmail.com>
6
+ Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
7
+ License: Copyright (c) 2016 The Python Packaging Authority (PyPA)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ of the Software, and to permit persons to whom the Software is furnished to do
14
+ so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://github.com/usso-io/usso-python
28
+ Project-URL: Bug Reports, https://github.com/usso-io/usso-python/issues
29
+ Project-URL: Funding, https://github.com/usso-io/usso-python
30
+ Project-URL: Say Thanks!, https://github.com/usso-io/usso-python
31
+ Project-URL: Source, https://github.com/usso-io/usso-python
32
+ Keywords: usso,sso,authentication,security,fastapi,django
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Topic :: Software Development :: Build Tools
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.8
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3 :: Only
44
+ Requires-Python: >=3.8
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE.txt
47
+ Requires-Dist: peppercorn
48
+ Provides-Extra: fastapi
49
+ Requires-Dist: fastapi>=0.65.0; extra == "fastapi"
50
+ Requires-Dist: uvicorn[standard]>=0.13.0; extra == "fastapi"
51
+ Provides-Extra: django
52
+ Requires-Dist: Django>=3.2; extra == "django"
53
+ Provides-Extra: dev
54
+ Requires-Dist: check-manifest; extra == "dev"
55
+ Provides-Extra: test
56
+ Requires-Dist: coverage; extra == "test"
57
+
58
+ # USSO-Client
59
+
60
+ The USSO-Client provides a universal single sign-on (SSO) integration for microservices, making it easy to add secure, scalable authentication across different frameworks. This client simplifies the process of connecting any microservice to the USSO service.
61
+
62
+ ## Features
63
+
64
+ - **Core SSO Integration**: Use the USSO core client for basic SSO functionality across any Python application.
65
+ - **Framework-Specific Modules**:
66
+ - **FastAPI Integration**: Specialized support for FastAPI applications, enabling async authentication mechanisms tailored to FastAPI's event loop.
67
+ - *Django Integration* (Coming soon): Customizable Django authentication backend that integrates seamlessly with Django's user management and middleware architecture.
68
+
69
+ ## Installation
70
+
71
+ Install the USSO client using pip:
72
+
73
+ ```bash
74
+ pip install usso-client
75
+ ```
76
+
77
+ To add framework-specific support, use the following commands:
78
+
79
+ For FastAPI:
80
+
81
+ ```bash
82
+ pip install "usso-client[fastapi]"
83
+ ```
84
+
85
+ ## Quick Start
86
+ Follow the quick start guides in the documentation to integrate USSO in your application.
87
+
88
+ ## Contributing
89
+ Contributions are welcome! See CONTRIBUTING.md for more details on how to get involved.
90
+
91
+ ## License
92
+ Distributed under the MIT License. See LICENSE for more information.
usso-0.4.0/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # USSO-Client
2
+
3
+ The USSO-Client provides a universal single sign-on (SSO) integration for microservices, making it easy to add secure, scalable authentication across different frameworks. This client simplifies the process of connecting any microservice to the USSO service.
4
+
5
+ ## Features
6
+
7
+ - **Core SSO Integration**: Use the USSO core client for basic SSO functionality across any Python application.
8
+ - **Framework-Specific Modules**:
9
+ - **FastAPI Integration**: Specialized support for FastAPI applications, enabling async authentication mechanisms tailored to FastAPI's event loop.
10
+ - *Django Integration* (Coming soon): Customizable Django authentication backend that integrates seamlessly with Django's user management and middleware architecture.
11
+
12
+ ## Installation
13
+
14
+ Install the USSO client using pip:
15
+
16
+ ```bash
17
+ pip install usso-client
18
+ ```
19
+
20
+ To add framework-specific support, use the following commands:
21
+
22
+ For FastAPI:
23
+
24
+ ```bash
25
+ pip install "usso-client[fastapi]"
26
+ ```
27
+
28
+ ## Quick Start
29
+ Follow the quick start guides in the documentation to integrate USSO in your application.
30
+
31
+ ## Contributing
32
+ Contributions are welcome! See CONTRIBUTING.md for more details on how to get involved.
33
+
34
+ ## License
35
+ Distributed under the MIT License. See LICENSE for more information.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "usso"
7
+ version = "0.4.0"
8
+ description = "A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {file = "LICENSE.txt"}
12
+ keywords = ["usso", "sso", "authentication", "security", "fastapi", "django"]
13
+ authors = [
14
+ {name = "Mahdi Kiani", email = "mahdikiany@gmail.com"}
15
+ ]
16
+ maintainers = [
17
+ {name = "Mahdi Kiani", email = "mahdikiany@gmail.com"}
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "Topic :: Software Development :: Build Tools",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.8",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3 :: Only",
31
+ ]
32
+ dependencies = [
33
+ "peppercorn" # Example main dependency
34
+ ]
35
+ optional-dependencies = {"fastapi" = ["fastapi>=0.65.0", "uvicorn[standard]>=0.13.0"],"django" = ["Django>=3.2"],"dev" = ["check-manifest"],"test" = ["coverage"]}
36
+
37
+ [project.urls]
38
+ "Homepage" = "https://github.com/usso-io/usso-python"
39
+ "Bug Reports" = "https://github.com/usso-io/usso-python/issues"
40
+ "Funding" = "https://github.com/usso-io/usso-python"
41
+ "Say Thanks!" = "https://github.com/usso-io/usso-python"
42
+ "Source" = "https://github.com/usso-io/usso-python"
43
+
44
+ [project.scripts]
45
+ usso = "usso:main"
46
+
47
+ [tool.setuptools]
48
+ package-data = {"usso" = ["*.dat"]}
usso-0.4.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ from .core import *
2
+ from usso_fastapi import integration as fastapi_integration
@@ -0,0 +1,30 @@
1
+ from functools import lru_cache
2
+ from typing import Optional, Tuple
3
+
4
+ import jwt
5
+ from pydantic import BaseModel
6
+
7
+
8
+ class UserData(BaseModel):
9
+ user_id: str
10
+ email: str | None = None
11
+ phone: str | None = None
12
+ authentication_method: str | None = None
13
+ is_active: bool = False
14
+ jti: str
15
+ data: dict | None = None
16
+ token: str | None = None
17
+
18
+
19
+ def get_authorization_scheme_param(
20
+ authorization_header_value: Optional[str],
21
+ ) -> Tuple[str, str]:
22
+ if not authorization_header_value:
23
+ return "", ""
24
+ scheme, _, param = authorization_header_value.partition(" ")
25
+ return scheme, param
26
+
27
+
28
+ @lru_cache
29
+ def get_jwks_keys(jwks_url):
30
+ return jwt.PyJWKClient(jwks_url)
@@ -0,0 +1,16 @@
1
+ error_messages = {
2
+ "invalid_signature": "Invalid signature",
3
+ "invalid_token": "Invalid token",
4
+ "expired_signature": "Expired signature",
5
+ "unauthorized": "Unauthorized",
6
+ }
7
+
8
+
9
+ class USSOException(Exception):
10
+ def __init__(self, status_code: int, error: str, message: str = None):
11
+ self.status_code = status_code
12
+ self.error = error
13
+ self.message = message
14
+ if message is None:
15
+ self.message = error_messages[error]
16
+ super().__init__(message)
File without changes
@@ -0,0 +1 @@
1
+ from .integration import *
@@ -0,0 +1,73 @@
1
+ import logging
2
+
3
+ import jwt
4
+ from fastapi import Request
5
+ from starlette.status import HTTP_401_UNAUTHORIZED
6
+
7
+ from usso.core import UserData, get_authorization_scheme_param, get_jwks_keys
8
+ from usso.exceptions import USSOException
9
+
10
+ logger = logging.getLogger("usso")
11
+
12
+
13
+ async def user_data_from_token(token: str, **kwargs) -> UserData | None:
14
+ """Return the user associated with a token value."""
15
+ try:
16
+ header = jwt.get_unverified_header(token)
17
+ jwks_url = header["jwk_url"]
18
+ jwks_client = get_jwks_keys(jwks_url)
19
+ # , headers=optional_custom_headers)
20
+ signing_key = jwks_client.get_signing_key_from_jwt(token)
21
+ decoded = jwt.decode(
22
+ token,
23
+ signing_key.key,
24
+ algorithms=["RS256"],
25
+ )
26
+ decoded["token"] = token
27
+
28
+ except jwt.exceptions.ExpiredSignatureError:
29
+ if kwargs.get("raise_exception"):
30
+ raise USSOException(
31
+ status_code=HTTP_401_UNAUTHORIZED, error="expired_signature"
32
+ )
33
+ return None
34
+ except jwt.exceptions.InvalidSignatureError:
35
+ if kwargs.get("raise_exception"):
36
+ raise USSOException(
37
+ status_code=HTTP_401_UNAUTHORIZED, error="invalid_signature"
38
+ )
39
+ return None
40
+ except jwt.exceptions.InvalidTokenError:
41
+ if kwargs.get("raise_exception"):
42
+ raise USSOException(
43
+ status_code=HTTP_401_UNAUTHORIZED, error="invalid_token"
44
+ )
45
+ return None
46
+ except Exception as e:
47
+ if kwargs.get("raise_exception"):
48
+ raise USSOException(
49
+ status_code=HTTP_401_UNAUTHORIZED, error="error", message=str(e)
50
+ )
51
+ logger.error(e)
52
+ return None
53
+
54
+ return UserData(**decoded)
55
+
56
+
57
+ async def jwt_access_security(request: Request) -> UserData | None:
58
+ """Return the user associated with a token value."""
59
+ kwargs = {}
60
+ authorization = request.headers.get("Authorization")
61
+ if authorization:
62
+ scheme, _, credentials = get_authorization_scheme_param(authorization)
63
+ if scheme.lower() == "bearer":
64
+ token = credentials
65
+ return await user_data_from_token(token, **kwargs)
66
+
67
+ cookie_token = request.cookies.get("access_token")
68
+ if cookie_token:
69
+ return await user_data_from_token(cookie_token, **kwargs)
70
+
71
+ if kwargs.get("raise_exception", True):
72
+ raise USSOException(status_code=HTTP_401_UNAUTHORIZED, error="unauthorized")
73
+ return None
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: usso
3
+ Version: 0.4.0
4
+ Summary: A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices.
5
+ Author-email: Mahdi Kiani <mahdikiany@gmail.com>
6
+ Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
7
+ License: Copyright (c) 2016 The Python Packaging Authority (PyPA)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
10
+ this software and associated documentation files (the "Software"), to deal in
11
+ the Software without restriction, including without limitation the rights to
12
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ of the Software, and to permit persons to whom the Software is furnished to do
14
+ so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://github.com/usso-io/usso-python
28
+ Project-URL: Bug Reports, https://github.com/usso-io/usso-python/issues
29
+ Project-URL: Funding, https://github.com/usso-io/usso-python
30
+ Project-URL: Say Thanks!, https://github.com/usso-io/usso-python
31
+ Project-URL: Source, https://github.com/usso-io/usso-python
32
+ Keywords: usso,sso,authentication,security,fastapi,django
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Topic :: Software Development :: Build Tools
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.8
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3 :: Only
44
+ Requires-Python: >=3.8
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE.txt
47
+ Requires-Dist: peppercorn
48
+ Provides-Extra: fastapi
49
+ Requires-Dist: fastapi>=0.65.0; extra == "fastapi"
50
+ Requires-Dist: uvicorn[standard]>=0.13.0; extra == "fastapi"
51
+ Provides-Extra: django
52
+ Requires-Dist: Django>=3.2; extra == "django"
53
+ Provides-Extra: dev
54
+ Requires-Dist: check-manifest; extra == "dev"
55
+ Provides-Extra: test
56
+ Requires-Dist: coverage; extra == "test"
57
+
58
+ # USSO-Client
59
+
60
+ The USSO-Client provides a universal single sign-on (SSO) integration for microservices, making it easy to add secure, scalable authentication across different frameworks. This client simplifies the process of connecting any microservice to the USSO service.
61
+
62
+ ## Features
63
+
64
+ - **Core SSO Integration**: Use the USSO core client for basic SSO functionality across any Python application.
65
+ - **Framework-Specific Modules**:
66
+ - **FastAPI Integration**: Specialized support for FastAPI applications, enabling async authentication mechanisms tailored to FastAPI's event loop.
67
+ - *Django Integration* (Coming soon): Customizable Django authentication backend that integrates seamlessly with Django's user management and middleware architecture.
68
+
69
+ ## Installation
70
+
71
+ Install the USSO client using pip:
72
+
73
+ ```bash
74
+ pip install usso-client
75
+ ```
76
+
77
+ To add framework-specific support, use the following commands:
78
+
79
+ For FastAPI:
80
+
81
+ ```bash
82
+ pip install "usso-client[fastapi]"
83
+ ```
84
+
85
+ ## Quick Start
86
+ Follow the quick start guides in the documentation to integrate USSO in your application.
87
+
88
+ ## Contributing
89
+ Contributions are welcome! See CONTRIBUTING.md for more details on how to get involved.
90
+
91
+ ## License
92
+ Distributed under the MIT License. See LICENSE for more information.
@@ -0,0 +1,16 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ src/usso/__init__.py
5
+ src/usso/core.py
6
+ src/usso/exceptions.py
7
+ src/usso/package_data.dat
8
+ src/usso.egg-info/PKG-INFO
9
+ src/usso.egg-info/SOURCES.txt
10
+ src/usso.egg-info/dependency_links.txt
11
+ src/usso.egg-info/entry_points.txt
12
+ src/usso.egg-info/requires.txt
13
+ src/usso.egg-info/top_level.txt
14
+ src/usso/usso_fastapi/__init__.py
15
+ src/usso/usso_fastapi/integration.py
16
+ tests/test_simple.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ usso = usso:main
@@ -0,0 +1,14 @@
1
+ peppercorn
2
+
3
+ [dev]
4
+ check-manifest
5
+
6
+ [django]
7
+ Django>=3.2
8
+
9
+ [fastapi]
10
+ fastapi>=0.65.0
11
+ uvicorn[standard]>=0.13.0
12
+
13
+ [test]
14
+ coverage
@@ -0,0 +1 @@
1
+ usso
@@ -0,0 +1,14 @@
1
+ # the inclusion of the tests module is not meant to offer best practices for
2
+ # testing in general, but rather to support the `find_packages` example in
3
+ # setup.py that excludes installing the "tests" package
4
+
5
+ import unittest
6
+
7
+
8
+ class TestSimple(unittest.TestCase):
9
+ def test_add_one(self):
10
+ self.assertEqual(5 + 1, 6)
11
+
12
+
13
+ if __name__ == "__main__":
14
+ unittest.main()