-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename the library, support for DI, v1 🚀
- Loading branch information
1 parent
617840f
commit 053aa70
Showing
54 changed files
with
1,484 additions
and
878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ __pycache__ | |
*.egg-info | ||
*.tar.gz | ||
.mypy_cache | ||
junit | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,63 @@ | ||
.PHONY: release test | ||
|
||
|
||
lint-types: | ||
mypy neoteroi --explicit-package-bases | ||
|
||
|
||
artifacts: test | ||
python setup.py sdist bdist_wheel | ||
python -m build | ||
|
||
|
||
clean: | ||
rm -rf dist/ | ||
|
||
|
||
prepforbuild: | ||
pip install --upgrade twine setuptools wheel | ||
pip install build | ||
|
||
|
||
build: | ||
python -m build | ||
|
||
uploadtest: | ||
twine upload --repository-url https://test.pypi.org/legacy/ dist/* | ||
|
||
test-release: | ||
twine upload --repository testpypi dist/* | ||
|
||
release: clean artifacts | ||
twine upload --repository-url https://upload.pypi.org/legacy/ dist/* | ||
|
||
release: | ||
twine upload --repository pypi dist/* | ||
|
||
|
||
test: | ||
python -m pytest | ||
|
||
|
||
testcov: | ||
python -m pytest --cov-report html --cov=guardpost tests/ | ||
test-cov: | ||
python -m pytest --cov-report html --cov=neoteroi tests/ | ||
|
||
|
||
lint: check-flake8 check-isort check-black | ||
|
||
format: | ||
@isort neoteroi 2>&1 | ||
@isort tests 2>&1 | ||
@black neoteroi 2>&1 | ||
@black tests 2>&1 | ||
|
||
check-flake8: | ||
@echo "$(BOLD)Checking flake8$(RESET)" | ||
@flake8 neoteroi 2>&1 | ||
@flake8 tests 2>&1 | ||
|
||
|
||
check-isort: | ||
@echo "$(BOLD)Checking isort$(RESET)" | ||
@isort --check-only neoteroi 2>&1 | ||
@isort --check-only tests 2>&1 | ||
|
||
|
||
check-black: ## Run the black tool in check mode only (won't modify files) | ||
@echo "$(BOLD)Checking black$(RESET)" | ||
@black --check neoteroi 2>&1 | ||
@black --check tests 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,64 @@ | ||
[![Build](https://github.com/Neoteroi/guardpost/workflows/Build/badge.svg)](https://github.com/Neoteroi/guardpost/actions?query=workflow%3ABuild) | ||
[![pypi](https://img.shields.io/pypi/v/guardpost.svg?color=blue)](https://pypi.org/project/guardpost/) | ||
[![versions](https://img.shields.io/pypi/pyversions/guardpost.svg)](https://github.com/Neoteroi/guardpost) | ||
[![license](https://img.shields.io/github/license/Neoteroi/guardpost.svg)](https://github.com/Neoteroi/guardpost/blob/master/LICENSE) | ||
[![codecov](https://codecov.io/gh/Neoteroi/guardpost/branch/master/graph/badge.svg?token=sBKZG2D1bZ)](https://codecov.io/gh/Neoteroi/guardpost) | ||
[![pypi](https://img.shields.io/pypi/v/neoteroi-auth.svg?color=blue)](https://pypi.org/project/neoteroi-auth/) | ||
[![versions](https://img.shields.io/pypi/pyversions/neoteroi-auth.svg)](https://github.com/Neoteroi/guardpost) | ||
[![license](https://img.shields.io/github/license/Neoteroi/guardpost.svg)](https://github.com/Neoteroi/guardpost/blob/main/LICENSE) | ||
[![codecov](https://codecov.io/gh/Neoteroi/guardpost/branch/main/graph/badge.svg?token=sBKZG2D1bZ)](https://codecov.io/gh/Neoteroi/guardpost) | ||
|
||
# GuardPost | ||
GuardPost provides a basic framework to handle authentication and authorization | ||
in any kind of Python application. | ||
# Authentication and authorization framework for Python apps | ||
Basic framework to handle authentication and authorization in asynchronous | ||
Python applications. | ||
|
||
**Features:** | ||
|
||
- strategy to implement authentication (who or what is using a service?) | ||
- strategy to implement authorization (is the acting identity authorized to do a certain action?) | ||
- support for dependency injection for classes handling authentication and | ||
authorization requirements | ||
- built-in support for JSON Web Tokens (JWTs) authentication | ||
|
||
This library is freely inspired by [authorization in ASP.NET | ||
Core](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2); | ||
although its implementation is extremely different. | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install guardpost | ||
pip install neoteroi-auth | ||
``` | ||
|
||
To install with support for `JSON Web Tokens (JWTs)` validation: | ||
|
||
``` | ||
pip install guardpost[jwt] | ||
pip install neoteroi-auth[jwt] | ||
``` | ||
|
||
This library is freely inspired by [authorization in ASP.NET | ||
Core](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2); | ||
although its implementation is extremely different. | ||
|
||
Notable differences are: | ||
1. GuardPost is abstracted from the code that executes it, so it's not bound to | ||
the context of a web framework. | ||
1. GuardPost implements both classes for use with synchronous code (not | ||
necessarily I/O bound), and classes using `async/await` syntax (optimized | ||
for authentication and authorization rules that involve I/O bound operations | ||
such as web requests and communications with databases). | ||
1. GuardPost leverages Python function decorators for the authorization part, | ||
so any function can be wrapped to be executed after handling authorization. | ||
1. The code API is simpler. | ||
|
||
## More documentation and examples | ||
For documentation and | ||
[examples](https://github.com/RobertoPrevato/GuardPost/wiki/Examples), refer to | ||
the project [Wiki](https://github.com/RobertoPrevato/GuardPost/wiki). | ||
|
||
To see how `guardpost` is used in `blacksheep` web framework, read the | ||
documentation here: | ||
### Examples | ||
|
||
* [Authentication](https://www.neoteroi.dev/blacksheep/authentication/) | ||
* [Authorization](https://www.neoteroi.dev/blacksheep/authorization/) | ||
|
||
## Both for async/await and synchronous code | ||
GuardPost can be used both with async/await code and with synchronous code, | ||
according to use cases and users' preference. | ||
For examples, refer to the [examples folder](./examples). | ||
|
||
## If you have doubts about authentication vs authorization... | ||
`Authentication` answers the question: _Who is the user who is executing the | ||
`Authentication` answers the question: _Who is the user who is initiating the | ||
action?_, or more in general: _Who is the user, or what is the service, that is | ||
executing the action?_. | ||
initiating the action?_. | ||
|
||
`Authorization` answers the question: _Is the user, or service, authorized to | ||
do something?_. | ||
|
||
Usually, to implement authorization, is necessary to have the context of the | ||
entity that is executing the action. Anyway, the two things are logically | ||
separated and GuardPost is designed to keep them separate. | ||
entity that is executing the action. | ||
|
||
## Usage in BlackSheep | ||
`guardpost` is used in the [BlackSheep](https://www.neoteroi.dev/blacksheep/) | ||
web framework to implement [authentication and authorization | ||
`neoteroi-auth` is used in the second version of the | ||
[BlackSheep](https://www.neoteroi.dev/blacksheep/) web framework, to implement | ||
[authentication and authorization | ||
strategies](https://www.neoteroi.dev/blacksheep/authentication/) for request | ||
handlers. | ||
|
||
To see how `neoteroi-auth` is used in `blacksheep` web framework, read: | ||
|
||
* [Authentication](https://www.neoteroi.dev/blacksheep/authentication/) | ||
* [Authorization](https://www.neoteroi.dev/blacksheep/authorization/) | ||
|
||
# Documentation | ||
|
||
Under construction. 🚧 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Generates a README.md file for the examples folder. | ||
""" | ||
|
||
import glob | ||
import importlib | ||
import sys | ||
|
||
examples = [file for file in glob.glob("./examples/*.py")] | ||
examples.sort() | ||
sys.path.append("./examples") | ||
|
||
with open("./examples/README.md", mode="wt", encoding="utf8 ") as examples_readme: | ||
examples_readme.write( | ||
"<!-- generated file, to update use: python examples-summary.py -->\n\n" | ||
) | ||
examples_readme.write("""# Examples""") | ||
|
||
for file_path in examples: | ||
if "__init__" in file_path: | ||
continue | ||
|
||
module_name = file_path.replace("./examples/", "").replace(".py", "") | ||
|
||
module = importlib.import_module(module_name) | ||
|
||
if not module.__doc__: | ||
continue | ||
|
||
examples_readme.write(f"\n\n## {module_name}.py\n") | ||
examples_readme.write(str(module.__doc__)) |
Oops, something went wrong.